Skip to content

Commit 22a37e3

Browse files
authored
Add --stash as alternative to --clean to update-checkout (#71178)
Use of `--clean` can lead to irreversible loss of uncommitted data. We still need to reset Swift project repositories to a clean state, but without deleting all in-progress changes. Passing `--stash` instead of (or in addition to) `--clean` will preserve uncommitted changes in stashes of corresponding repositories.
1 parent ba81a08 commit 22a37e3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def get_branch_for_repo(config, repo_name, scheme_name, scheme_map,
148148

149149
def update_single_repository(pool_args):
150150
source_root, config, repo_name, scheme_name, scheme_map, tag, timestamp, \
151-
reset_to_remote, should_clean, cross_repos_pr = pool_args
151+
reset_to_remote, should_clean, should_stash, cross_repos_pr = pool_args
152152
repo_path = os.path.join(source_root, repo_name)
153153
if not os.path.isdir(repo_path) or os.path.islink(repo_path):
154154
return
@@ -171,9 +171,13 @@ def update_single_repository(pool_args):
171171
checkout_target)
172172

173173
# The clean option restores a repository to pristine condition.
174-
if should_clean:
175-
shell.run(['git', 'clean', '-fdx'],
176-
echo=True, prefix=prefix)
174+
if should_clean or should_stash:
175+
if should_stash:
176+
shell.run(['git', 'stash'],
177+
echo=True, prefix=prefix)
178+
elif should_clean:
179+
shell.run(['git', 'clean', '-fdx'],
180+
echo=True, prefix=prefix)
177181
shell.run(['git', 'submodule', 'foreach', '--recursive',
178182
'git', 'clean', '-fdx'],
179183
echo=True, prefix=prefix)
@@ -343,6 +347,7 @@ def update_all_repositories(args, config, scheme_name, scheme_map, cross_repos_p
343347
timestamp,
344348
args.reset_to_remote,
345349
args.clean,
350+
args.stash,
346351
cross_repos_pr]
347352
pool_args.append(my_args)
348353

@@ -605,7 +610,11 @@ def main():
605610
action='store_true')
606611
parser.add_argument(
607612
'--clean',
608-
help='Clean unrelated files from each repository.',
613+
help='Clean untracked files from each repository.',
614+
action='store_true')
615+
parser.add_argument(
616+
'--stash',
617+
help='Stash untracked files from each repository.',
609618
action='store_true')
610619
parser.add_argument(
611620
"--config",

0 commit comments

Comments
 (0)