Skip to content

Commit bcdb4cf

Browse files
authored
Merge pull request #7165 from erg/fix-update-checkout-fetch
utils/update-checkout: Do any ``git checkout`` before the ``git fetch``.
2 parents 18361c9 + 07ddf07 commit bcdb4cf

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)