Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d4cedd

Browse files
author
Christophe Triquet
committedJun 19, 2024·
Add remote update support
1 parent c322bea commit 5d4cedd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎nbgitpuller/pull.py

+25
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ def resolve_default_branch(self):
133133
logging.exception(m)
134134
raise ValueError(m)
135135

136+
def check_and_update_remote(self):
137+
"""
138+
Checks the Git remote URL and update it if deprecated
139+
140+
Only allows update of creds in URL e.g. access token.
141+
Git repo must be unchanged.
142+
"""
143+
remote_url = subprocess.run(
144+
["git", "config", "remote.origin.url"],
145+
cwd=self.repo_dir,
146+
capture_output=True,
147+
text=True,
148+
check=True
149+
).stdout.strip()
150+
151+
if (
152+
"@" in self.git_url and "@" in remote_url
153+
and self.git_url.rsplit("@", 1)[0] != remote_url.rsplit("@", 1)[0]
154+
):
155+
subprocess.run(
156+
["git", "remote", "set-url", "origin", self.git_url],
157+
cwd=self.repo_dir
158+
)
159+
136160
def pull(self):
137161
"""
138162
Pull selected repo from a remote git repository,
@@ -141,6 +165,7 @@ def pull(self):
141165
if not os.path.exists(self.repo_dir):
142166
yield from self.initialize_repo()
143167
else:
168+
self.check_and_update_remote()
144169
yield from self.update()
145170

146171
def initialize_repo(self):

0 commit comments

Comments
 (0)