@@ -32,12 +32,14 @@ sys.path.append(os.path.join(SCRIPT_DIR, 'swift_build_support'))
32
32
from swift_build_support import shell # noqa (E402)
33
33
34
34
35
- def update_single_repository (repo_path , branch ):
35
+ def update_single_repository (repo_path , branch , reset_to_remote ):
36
36
if not os .path .isdir (repo_path ):
37
37
return
38
38
39
39
print ("--- Updating '" + repo_path + "' ---" )
40
40
with shell .pushd (repo_path , dry_run = False , echo = False ):
41
+ shell .call (["git" , "fetch" ], echo = False )
42
+
41
43
if branch :
42
44
status = shell .capture (['git' , 'status' , '--porcelain' , '-uno' ],
43
45
echo = False )
@@ -47,10 +49,16 @@ def update_single_repository(repo_path, branch):
47
49
exit (1 )
48
50
shell .call (['git' , 'checkout' , branch ], echo = False )
49
51
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
+
50
59
# Prior to Git 2.6, this is the way to do a "git pull
51
60
# --rebase" that respects rebase.autostash. See
52
61
# http://stackoverflow.com/a/30209750/125349
53
- shell .call (["git" , "fetch" ], echo = False )
54
62
shell .call (["git" , "rebase" , "FETCH_HEAD" ], echo = False )
55
63
shell .call (["git" , "submodule" , "update" , "--recursive" ],
56
64
echo = False )
@@ -74,7 +82,8 @@ def update_all_repositories(args, config, scheme_name):
74
82
break
75
83
76
84
update_single_repository (os .path .join (SWIFT_SOURCE_ROOT , repo_name ),
77
- repo_branch )
85
+ repo_branch ,
86
+ args .reset_to_remote )
78
87
79
88
80
89
def obtain_additional_swift_sources (
@@ -181,6 +190,10 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
181
190
help = 'Obtain Sources for specific branch' ,
182
191
metavar = 'BRANCH' ,
183
192
dest = 'scheme' )
193
+ parser .add_argument (
194
+ '--reset-to-remote' ,
195
+ help = 'Reset each branch to the remote state.' ,
196
+ action = 'store_true' )
184
197
parser .add_argument (
185
198
"--config" ,
186
199
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.""")
197
210
validate_config (config )
198
211
199
212
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.
202
215
if scheme is None :
203
216
scheme = config ['default-branch-scheme' ]
204
217
0 commit comments