Skip to content

Commit dea09e1

Browse files
Merge pull request #72704 from AnthonyLatsis/update-checkout-stash
update-checkout: Patch up a few flaws with `--stash`
2 parents 302b010 + baa0cfd commit dea09e1

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,34 @@ def update_single_repository(pool_args):
170170
repo_name,
171171
checkout_target)
172172

173-
# The clean option restores a repository to pristine condition.
173+
# The '--clean' and '--stash' options
174+
# 1. clear the index and working tree ('--stash' stashes those
175+
# changes rather than discarding them)
176+
# 2. delete ignored files
177+
# 3. abort an ongoing rebase
174178
if should_clean or should_stash:
179+
180+
def run_for_repo_and_each_submodule_rec(cmd):
181+
shell.run(cmd, echo=True, prefix=prefix)
182+
shell.run(
183+
["git", "submodule", "foreach", "--recursive"] + cmd,
184+
echo=True,
185+
prefix=prefix,
186+
)
187+
175188
if should_stash:
176-
shell.run(['git', 'stash'],
177-
echo=True, prefix=prefix)
189+
# Stash tracked and untracked changes.
190+
run_for_repo_and_each_submodule_rec(["git", "stash", "-u"])
178191
elif should_clean:
179-
shell.run(['git', 'clean', '-fdx'],
180-
echo=True, prefix=prefix)
181-
shell.run(['git', 'submodule', 'foreach', '--recursive',
182-
'git', 'clean', '-fdx'],
183-
echo=True, prefix=prefix)
184-
shell.run(['git', 'submodule', 'foreach', '--recursive',
185-
'git', 'reset', '--hard', 'HEAD'],
186-
echo=True, prefix=prefix)
187-
shell.run(['git', 'reset', '--hard', 'HEAD'],
188-
echo=True, prefix=prefix)
192+
# Delete tracked changes.
193+
run_for_repo_and_each_submodule_rec(
194+
["git", "reset", "--hard", "HEAD"]
195+
)
196+
197+
# Delete untracked changes and ignored files.
198+
run_for_repo_and_each_submodule_rec(["git", "clean", "-fdx"])
199+
del run_for_repo_and_each_submodule_rec
200+
189201
# It is possible to reset --hard and still be mid-rebase.
190202
try:
191203
shell.run(['git', 'rebase', '--abort'],
@@ -609,13 +621,17 @@ def main():
609621
help='Reset each branch to the remote state.',
610622
action='store_true')
611623
parser.add_argument(
612-
'--clean',
613-
help='Clean untracked files from each repository.',
614-
action='store_true')
624+
"--clean",
625+
help="""Delete tracked and untracked changes, ignored files, and abort
626+
an ongoing rebase, if any, before updating a repository.""",
627+
action="store_true",
628+
)
615629
parser.add_argument(
616-
'--stash',
617-
help='Stash untracked files from each repository.',
618-
action='store_true')
630+
"--stash",
631+
help="""Stash tracked and untracked changes, delete ignored files, and
632+
abort an ongoing rebase, if any, before updating a repository.""",
633+
action="store_true",
634+
)
619635
parser.add_argument(
620636
"--config",
621637
default=os.path.join(SCRIPT_DIR, os.pardir,

0 commit comments

Comments
 (0)