Skip to content

update-checkout: Patch up a few flaws with --stash #72704

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
Apr 3, 2024
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
54 changes: 35 additions & 19 deletions utils/update_checkout/update_checkout/update_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,34 @@ def update_single_repository(pool_args):
repo_name,
checkout_target)

# The clean option restores a repository to pristine condition.
# The '--clean' and '--stash' options
# 1. clear the index and working tree ('--stash' stashes those
# changes rather than discarding them)
# 2. delete ignored files
# 3. abort an ongoing rebase
if should_clean or should_stash:

def run_for_repo_and_each_submodule_rec(cmd):
shell.run(cmd, echo=True, prefix=prefix)
shell.run(
["git", "submodule", "foreach", "--recursive"] + cmd,
echo=True,
prefix=prefix,
)

if should_stash:
shell.run(['git', 'stash'],
echo=True, prefix=prefix)
# Stash tracked and untracked changes.
run_for_repo_and_each_submodule_rec(["git", "stash", "-u"])
elif should_clean:
shell.run(['git', 'clean', '-fdx'],
echo=True, prefix=prefix)
shell.run(['git', 'submodule', 'foreach', '--recursive',
'git', 'clean', '-fdx'],
echo=True, prefix=prefix)
shell.run(['git', 'submodule', 'foreach', '--recursive',
'git', 'reset', '--hard', 'HEAD'],
echo=True, prefix=prefix)
shell.run(['git', 'reset', '--hard', 'HEAD'],
echo=True, prefix=prefix)
# Delete tracked changes.
run_for_repo_and_each_submodule_rec(
["git", "reset", "--hard", "HEAD"]
)

# Delete untracked changes and ignored files.
run_for_repo_and_each_submodule_rec(["git", "clean", "-fdx"])
del run_for_repo_and_each_submodule_rec

# It is possible to reset --hard and still be mid-rebase.
try:
shell.run(['git', 'rebase', '--abort'],
Expand Down Expand Up @@ -609,13 +621,17 @@ def main():
help='Reset each branch to the remote state.',
action='store_true')
parser.add_argument(
'--clean',
help='Clean untracked files from each repository.',
action='store_true')
"--clean",
help="""Delete tracked and untracked changes, ignored files, and abort
an ongoing rebase, if any, before updating a repository.""",
action="store_true",
)
parser.add_argument(
'--stash',
help='Stash untracked files from each repository.',
action='store_true')
"--stash",
help="""Stash tracked and untracked changes, delete ignored files, and
abort an ongoing rebase, if any, before updating a repository.""",
action="store_true",
)
parser.add_argument(
"--config",
default=os.path.join(SCRIPT_DIR, os.pardir,
Expand Down