Skip to content

utils/update-checkout: Do any git checkout before the git fetch. #7165

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

Merged
merged 1 commit into from
Jan 31, 2017
Merged
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
28 changes: 18 additions & 10 deletions utils/update-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,36 @@ def update_single_repository(args):
try:
print("Updating '" + repo_path + "'")
with shell.pushd(repo_path, dry_run=False, echo=False):
shell.run(["git", "fetch", "--recurse-submodules=yes"], echo=True)

# The clean option should restore a repository to pristine condition.
if should_clean:
shell.run(['git', 'clean', '-fdx'], echo=True)
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
'clean', '-fdx'], echo=True)
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
'reset', '--hard', 'HEAD'], echo=True)
shell.run(['git', 'reset', '--hard', 'HEAD'],
echo=True)
shell.run(['git', 'reset', '--hard', 'HEAD'], echo=True)
# It is possible to reset --hard and still be in the middle of a rebase.
try:
shell.run(['git', 'rebase', '--abort'], echo=True)
except:
pass

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

# If we were asked to reset to the specified branch, do the hard
# reset and return.
if reset_to_remote and not cross_repo:
shell.run(['git', 'reset', '--hard', "origin/%s" % branch],
echo=True)
return
# It's important that we checkout, fetch, and rebase, in order.
# .git/FETCH_HEAD updates the not-for-merge attributes based on which
# branch was checked out during the fetch.
shell.run(["git", "fetch", "--recurse-submodules=yes"], echo=True)

# If we were asked to reset to the specified branch, do the hard
# reset and return.
if branch and reset_to_remote and not cross_repo:
shell.run(['git', 'reset', '--hard', "origin/%s" % branch],
echo=True)
return

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