Skip to content

Commit 3952722

Browse files
committed
Merge pull request swiftlang#1169 from shahmishal/swift-2.2-branch
Support to checkout specific branch using update-checkout script
2 parents fc23740 + a06d04c commit 3952722

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

utils/update-checkout

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,83 +21,88 @@ from SwiftBuildSupport import (
2121
SWIFT_SOURCE_ROOT,
2222
WorkingDirectory,
2323
check_call,
24+
check_output,
2425
)
2526

26-
def update_working_copy(repo_path):
27+
def update_working_copy(repo_path, branch):
2728
if not os.path.isdir(repo_path):
2829
return
2930

3031
print("--- Updating '" + repo_path + "' ---")
3132
with WorkingDirectory(repo_path):
33+
if branch:
34+
status = check_output(['git', 'status', '--porcelain'])
35+
if status:
36+
print("Please, commit your changes.")
37+
print(status)
38+
exit(1)
39+
check_call(['git', 'checkout', branch])
40+
3241
# Prior to Git 2.6, this is the way to do a "git pull
3342
# --rebase" that respects rebase.autostash. See
3443
# http://stackoverflow.com/a/30209750/125349
35-
check_call([ "git", "fetch" ])
36-
check_call([ "git", "rebase", "FETCH_HEAD" ])
44+
check_call(["git", "fetch"])
45+
check_call(["git", "rebase", "FETCH_HEAD"])
3746

38-
def obtain_additional_swift_sources(opts = {'with_ssh': False}):
47+
def obtain_additional_swift_sources(with_ssh, branch):
3948
additional_repos = {
4049
'llvm': 'apple/swift-llvm',
4150
'clang': 'apple/swift-clang',
4251
'lldb': 'apple/swift-lldb',
4352
'cmark': 'apple/swift-cmark',
44-
'llbuild': 'apple/swift-llbuild',
45-
'swiftpm': 'apple/swift-package-manager',
46-
'swift-corelibs-xctest': 'apple/swift-corelibs-xctest',
47-
'swift-corelibs-foundation': 'apple/swift-corelibs-foundation',
4853
'swift-integration-tests': 'apple/swift-integration-tests',
4954
}
5055
for dir_name, repo in additional_repos.items():
5156
with WorkingDirectory(SWIFT_SOURCE_ROOT):
5257
if not os.path.isdir(os.path.join(dir_name, ".git")):
5358
print("--- Cloning '" + dir_name + "' ---")
54-
if opts['with_ssh'] is True:
59+
if with_ssh is True:
5560
remote = "[email protected]:" + repo + '.git'
5661
else:
5762
remote = "https://github.com/" + repo + '.git'
5863
check_call(['git', 'clone', remote, dir_name])
64+
if branch:
65+
src_path = SWIFT_SOURCE_ROOT + "/" + dir_name + "/" + ".git"
66+
check_call(['git', '--git-dir', src_path, '--work-tree', os.path.join(SWIFT_SOURCE_ROOT, dir_name), 'checkout', branch])
5967

6068
def main():
6169
parser = argparse.ArgumentParser(
6270
formatter_class=argparse.RawDescriptionHelpFormatter,
6371
description="""
6472
repositories.
6573
66-
By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
74+
By default, updates your checkouts of Swift, and LLDB.""")
6775
parser.add_argument("-a", "--all",
68-
help="also update checkouts of llbuild, LLVM, and Clang",
76+
help="also update checkouts of LLVM, and Clang",
6977
action="store_true")
7078
parser.add_argument("--clone",
7179
help="Obtain Sources for Swift and Related Projects",
7280
action="store_true")
7381
parser.add_argument("--clone-with-ssh",
7482
help="Obtain Sources for Swift and Related Projects via SSH",
7583
action="store_true")
84+
parser.add_argument("--branch",
85+
help="Obtain Sources for specific branch")
7686
args = parser.parse_args()
7787

78-
if args.clone:
79-
obtain_additional_swift_sources()
80-
return 0
88+
clone = args.clone
89+
clone_with_ssh = args.clone_with_ssh
90+
branch = args.branch
8191

82-
if args.clone_with_ssh:
83-
obtain_additional_swift_sources({'with_ssh': True})
92+
if clone or clone_with_ssh:
93+
obtain_additional_swift_sources(clone_with_ssh, branch)
8494
return 0
8595

8696
if args.all:
87-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llbuild"))
88-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llvm"))
89-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "clang"))
97+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llvm"), branch)
98+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "clang"), branch)
9099

91-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift"))
100+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift"), branch)
92101
update_working_copy(
93-
os.path.join(SWIFT_SOURCE_ROOT, "swift", "benchmark", "PerfTestSuite"))
94-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "SourceKit"))
95-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "cmark"))
96-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "lldb"))
97-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swiftpm"))
98-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-corelibs-foundation"))
99-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-corelibs-xctest"))
100-
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-integration-tests"))
102+
os.path.join(SWIFT_SOURCE_ROOT, "swift", "benchmark", "PerfTestSuite"), branch)
103+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "cmark"), branch)
104+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "lldb"), branch)
105+
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-integration-tests"), branch)
101106

102107
return 0
103108

0 commit comments

Comments
 (0)