From cf35029fa6e8534557154512cee990872a6a6075 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 26 Jan 2024 12:51:41 +0000 Subject: [PATCH 1/3] Add `--stash` as alternative to `--clean` to `update-checkout` Use of `--clean` can lead to irreversible loss of uncommitted data. It is still desirable to reset Swift project repositories to a clean state, but without deleting all of the in-progress changes. Passing `--stash` instead of (or in addition to) `--clean` will preserve uncommitted changes in stashes of corresponding repositories instead of completely deleting those. --- .../update_checkout/update_checkout.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/utils/update_checkout/update_checkout/update_checkout.py b/utils/update_checkout/update_checkout/update_checkout.py index 00143f702895c..fc4f3a7b3df59 100755 --- a/utils/update_checkout/update_checkout/update_checkout.py +++ b/utils/update_checkout/update_checkout/update_checkout.py @@ -148,7 +148,7 @@ def get_branch_for_repo(config, repo_name, scheme_name, scheme_map, def update_single_repository(pool_args): source_root, config, repo_name, scheme_name, scheme_map, tag, timestamp, \ - reset_to_remote, should_clean, cross_repos_pr = pool_args + reset_to_remote, should_clean, should_stash, cross_repos_pr = pool_args repo_path = os.path.join(source_root, repo_name) if not os.path.isdir(repo_path) or os.path.islink(repo_path): return @@ -171,9 +171,13 @@ def update_single_repository(pool_args): checkout_target) # The clean option restores a repository to pristine condition. - if should_clean: - shell.run(['git', 'clean', '-fdx'], - echo=True, prefix=prefix) + if should_clean or should_stash: + if should_stash: + shell.run(['git', 'stash'], + echo=True, prefix=prefix) + 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) @@ -343,6 +347,7 @@ def update_all_repositories(args, config, scheme_name, scheme_map, cross_repos_p timestamp, args.reset_to_remote, args.clean, + args.stash, cross_repos_pr] pool_args.append(my_args) @@ -607,6 +612,10 @@ def main(): '--clean', help='Clean unrelated files from each repository.', action='store_true') + parser.add_argument( + '--stash', + help='Stash unrelated files from each repository.', + action='store_true') parser.add_argument( "--config", default=os.path.join(SCRIPT_DIR, os.pardir, From b6e475bc418614aa43663acb64a77477fda5c1e0 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 21 Mar 2024 12:03:01 +0000 Subject: [PATCH 2/3] Apply suggestions from code review --- utils/update_checkout/update_checkout/update_checkout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/update_checkout/update_checkout/update_checkout.py b/utils/update_checkout/update_checkout/update_checkout.py index fc4f3a7b3df59..5f07c375dfb8e 100755 --- a/utils/update_checkout/update_checkout/update_checkout.py +++ b/utils/update_checkout/update_checkout/update_checkout.py @@ -610,11 +610,11 @@ def main(): action='store_true') parser.add_argument( '--clean', - help='Clean unrelated files from each repository.', + help='Clean untracked files from each repository.', action='store_true') parser.add_argument( '--stash', - help='Stash unrelated files from each repository.', + help='Stash untracked files from each repository.', action='store_true') parser.add_argument( "--config", From 3c8cdea48a27c85996e0edd69adfacff471eb52d Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 21 Mar 2024 16:30:50 +0000 Subject: [PATCH 3/3] Fix linter warnings --- utils/update_checkout/update_checkout/update_checkout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/update_checkout/update_checkout/update_checkout.py b/utils/update_checkout/update_checkout/update_checkout.py index 5f07c375dfb8e..843d4c055d1d0 100755 --- a/utils/update_checkout/update_checkout/update_checkout.py +++ b/utils/update_checkout/update_checkout/update_checkout.py @@ -174,10 +174,10 @@ def update_single_repository(pool_args): if should_clean or should_stash: if should_stash: shell.run(['git', 'stash'], - echo=True, prefix=prefix) + echo=True, prefix=prefix) elif should_clean: shell.run(['git', 'clean', '-fdx'], - echo=True, prefix=prefix) + echo=True, prefix=prefix) shell.run(['git', 'submodule', 'foreach', '--recursive', 'git', 'clean', '-fdx'], echo=True, prefix=prefix)