Skip to content

Commit

Permalink
Add --stash as alternative to --clean to update-checkout (#71178)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaxDesiatov committed Mar 21, 2024
1 parent ba81a08 commit 22a37e3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions utils/update_checkout/update_checkout/update_checkout.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -605,7 +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 untracked files from each repository.',
action='store_true')
parser.add_argument(
"--config",
Expand Down

0 comments on commit 22a37e3

Please sign in to comment.