Skip to content

Commit 7a589f1

Browse files
authored
Merge pull request josegonzalez#57 from acdha/reuse-existing-remotes
Avoid remote branch name churn
2 parents 9a91dd7 + 92c619c commit 7a589f1

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

bin/github-backup

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,21 @@ def fetch_repository(name,
741741

742742
if clone_exists:
743743
log_info('Updating {0} in {1}'.format(name, local_dir))
744-
git_command = ['git', 'remote', 'rm', 'origin']
745-
logging_subprocess(git_command, None, cwd=local_dir)
746-
git_command = ['git', 'remote', 'add', 'origin', remote_url]
747-
logging_subprocess(git_command, None, cwd=local_dir)
748-
git_command = ['git', 'fetch', '--all', '--tags', '--prune']
744+
745+
remotes = subprocess.check_output(['git', 'remote', 'show'],
746+
cwd=local_dir)
747+
remotes = [i.strip() for i in remotes.decode('utf-8')]
748+
749+
if 'origin' not in remotes:
750+
git_command = ['git', 'remote', 'rm', 'origin']
751+
logging_subprocess(git_command, None, cwd=local_dir)
752+
git_command = ['git', 'remote', 'add', 'origin', remote_url]
753+
logging_subprocess(git_command, None, cwd=local_dir)
754+
else:
755+
git_command = ['git', 'remote', 'set-url', 'origin', remote_url]
756+
logging_subprocess(git_command, None, cwd=local_dir)
757+
758+
git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune']
749759
logging_subprocess(git_command, None, cwd=local_dir)
750760
else:
751761
log_info('Cloning {0} repository from {1} to {2}'.format(

0 commit comments

Comments
 (0)