Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote update support #342

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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