Skip to content

Commit

Permalink
Add remote update support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Triquet committed Feb 27, 2024
1 parent 253c012 commit c00e434
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions nbgitpuller/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ def resolve_default_branch(self):
logging.exception(m)
raise ValueError(m)

def check_and_update_remote(self):
"""
Checks the Git remote URL and update it if deprecated
Only allows update of creds in URL e.g. access token.
Git repo must be unchanged.
"""
remote_url = subprocess.run(
["git", "config", "remote.origin.url"],
cwd=self.repo_dir,
capture_output=True,
text=True,
check=True
).stdout.strip()

if (
"@" in self.git_url and "@" in remote_url
and self.git_url.rsplit("@", 1)[0] != remote_url.rsplit("@", 1)[0]
):
subprocess.run(
["git", "remote", "set-url", "origin", self.git_url],
cwd=self.repo_dir
)

def pull(self):
"""
Pull selected repo from a remote git repository,
Expand All @@ -141,6 +165,7 @@ def pull(self):
if not os.path.exists(self.repo_dir):
yield from self.initialize_repo()
else:
self.check_and_update_remote()
yield from self.update()

def initialize_repo(self):
Expand Down

0 comments on commit c00e434

Please sign in to comment.