Skip to content

Commit 07ddf07

Browse files
author
Doug Coleman
committed
utils/update-checkout: Do any git checkout before the git fetch.
utils/update-checkout: Add a call to ``git rebase --abort`` when using the ``--clean`` option. Calling ``git fetch`` updates .git/FETCH_HEAD and marks all branches besides the currently checked out branch as not-for-merge. So tot ensure that the branch we want to merge is available for merging, we must do a checkout of that branch before updating the FETCH_HEAD file. We also must ensure that we have fetched before optionally resetting to remote. Fixes https://bugs.swift.org/browse/SR-3800. The --clean option is meant to restore your repository to a pristine condition, but there are cases where you can ``reset --hard`` and still be in the middle of a rebase. This is annoying across 10+ repositories, so if the user wants to --clean, then abort all rebases in progress.
1 parent 18361c9 commit 07ddf07

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

utils/update-checkout

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,36 @@ def update_single_repository(args):
4343
try:
4444
print("Updating '" + repo_path + "'")
4545
with shell.pushd(repo_path, dry_run=False, echo=False):
46-
shell.run(["git", "fetch", "--recurse-submodules=yes"], echo=True)
47-
46+
# The clean option should restore a repository to pristine condition.
4847
if should_clean:
4948
shell.run(['git', 'clean', '-fdx'], echo=True)
5049
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
5150
'clean', '-fdx'], echo=True)
5251
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
5352
'reset', '--hard', 'HEAD'], echo=True)
54-
shell.run(['git', 'reset', '--hard', 'HEAD'],
55-
echo=True)
53+
shell.run(['git', 'reset', '--hard', 'HEAD'], echo=True)
54+
# It is possible to reset --hard and still be in the middle of a rebase.
55+
try:
56+
shell.run(['git', 'rebase', '--abort'], echo=True)
57+
except:
58+
pass
5659

5760
if branch:
5861
shell.run(['git', 'status', '--porcelain', '-uno'],
5962
echo=False)
6063
shell.run(['git', 'checkout', branch], echo=True)
6164

62-
# If we were asked to reset to the specified branch, do the hard
63-
# reset and return.
64-
if reset_to_remote and not cross_repo:
65-
shell.run(['git', 'reset', '--hard', "origin/%s" % branch],
66-
echo=True)
67-
return
65+
# It's important that we checkout, fetch, and rebase, in order.
66+
# .git/FETCH_HEAD updates the not-for-merge attributes based on which
67+
# branch was checked out during the fetch.
68+
shell.run(["git", "fetch", "--recurse-submodules=yes"], echo=True)
69+
70+
# If we were asked to reset to the specified branch, do the hard
71+
# reset and return.
72+
if branch and reset_to_remote and not cross_repo:
73+
shell.run(['git', 'reset', '--hard', "origin/%s" % branch],
74+
echo=True)
75+
return
6876

6977
# Prior to Git 2.6, this is the way to do a "git pull
7078
# --rebase" that respects rebase.autostash. See

0 commit comments

Comments
 (0)