Skip to content

Commit ecddf6b

Browse files
committed
[update-checkout] Add an option --reset-to-remote that can be used with --branch to reset a selected scheme's local branches to the remote branch state.
This is useful when one has done some quick prototyping work on the various repos of a scheme that one wants to quickly get rid of.
1 parent cd59716 commit ecddf6b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

utils/update-checkout

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ sys.path.append(os.path.join(SCRIPT_DIR, 'swift_build_support'))
3232
from swift_build_support import shell # noqa (E402)
3333

3434

35-
def update_single_repository(repo_path, branch):
35+
def update_single_repository(repo_path, branch, reset_to_remote):
3636
if not os.path.isdir(repo_path):
3737
return
3838

3939
print("--- Updating '" + repo_path + "' ---")
4040
with shell.pushd(repo_path, dry_run=False, echo=False):
41+
shell.call(["git", "fetch"], echo=False)
42+
4143
if branch:
4244
status = shell.capture(['git', 'status', '--porcelain', '-uno'],
4345
echo=False)
@@ -47,10 +49,16 @@ def update_single_repository(repo_path, branch):
4749
exit(1)
4850
shell.call(['git', 'checkout', branch], echo=False)
4951

52+
# If we were asked to reset to the specified branch, do the hard
53+
# reset and return.
54+
if reset_to_remote:
55+
shell.call(['git', 'reset', '--hard', "origin/%s" % branch],
56+
echo=False)
57+
return
58+
5059
# Prior to Git 2.6, this is the way to do a "git pull
5160
# --rebase" that respects rebase.autostash. See
5261
# http://stackoverflow.com/a/30209750/125349
53-
shell.call(["git", "fetch"], echo=False)
5462
shell.call(["git", "rebase", "FETCH_HEAD"], echo=False)
5563
shell.call(["git", "submodule", "update", "--recursive"],
5664
echo=False)
@@ -74,7 +82,8 @@ def update_all_repositories(args, config, scheme_name):
7482
break
7583

7684
update_single_repository(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
77-
repo_branch)
85+
repo_branch,
86+
args.reset_to_remote)
7887

7988

8089
def obtain_additional_swift_sources(
@@ -181,6 +190,10 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
181190
help='Obtain Sources for specific branch',
182191
metavar='BRANCH',
183192
dest='scheme')
193+
parser.add_argument(
194+
'--reset-to-remote',
195+
help='Reset each branch to the remote state.',
196+
action='store_true')
184197
parser.add_argument(
185198
"--config",
186199
default=os.path.join(SCRIPT_DIR, "update-checkout-config.json"),
@@ -197,8 +210,8 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
197210
validate_config(config)
198211

199212
if clone or clone_with_ssh:
200-
# If branch is None, default to using the default branch alias specified by
201-
# our configuration file.
213+
# If branch is None, default to using the default branch alias
214+
# specified by our configuration file.
202215
if scheme is None:
203216
scheme = config['default-branch-scheme']
204217

0 commit comments

Comments
 (0)