Skip to content

Commit c89dca8

Browse files
Add ability to specify project branch to install
1 parent f9a31a2 commit c89dca8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

docs/markdown/fallback-wraptool.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ To list all available wraps:
1717
To install a wrap, go to your source root, make sure that the
1818
`subprojects` directory exists and run this command:
1919

20-
ghwt.py install <projectname>
20+
ghwt.py install <projectname> [<branchname>]
2121

2222
This will stage the subproject ready to use. If you have multiple
2323
subprojects you need to download them all manually.
2424

25+
Specifying branch name is optional. If not specified, the list
26+
of potential branches is sorted alphabetically and the last branch is
27+
used.
28+
2529
*Note* The tool was added in 0.32.0, for versions older than that you
2630
need to delete the `foo.wrap` file to work around this issue.
2731

ghwt.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def unpack(sproj, branch):
8181
shutil.rmtree(os.path.join(outdir, '.git'))
8282
os.unlink(ofilename)
8383

84-
def install(sproj):
84+
def install(sproj, requested_branch=None):
8585
if not os.path.isdir(spdir):
8686
print('Run this in your source root and make sure there is a subprojects directory in it.')
8787
return 1
@@ -90,23 +90,39 @@ def install(sproj):
9090
blist = [b for b in blist if b != 'master']
9191
blist.sort()
9292
branch = blist[-1]
93+
if requested_branch is not None:
94+
if requested_branch in blist:
95+
branch = requested_branch
96+
else:
97+
print('Could not find user-requested branch', requested_branch)
98+
print('Available branches for', sproj, ':')
99+
print(blist)
100+
return 1
93101
print('Using branch', branch)
94102
return unpack(sproj, branch)
95103

104+
def print_help():
105+
print('Usage:')
106+
print(sys.argv[0], 'list')
107+
print(sys.argv[0], 'install', 'package_name', '[branch_name]')
108+
96109
def run(args):
97110
if not args or args[0] == '-h' or args[0] == '--help':
98-
print(sys.argv[0], 'list/install', 'package_name')
111+
print_help()
99112
return 1
100113
command = args[0]
101114
args = args[1:]
102115
if command == 'list':
103116
list_projects()
104117
return 0
105118
elif command == 'install':
106-
if len(args) != 1:
107-
print('Install requires exactly one argument.')
119+
if len(args) == 1:
120+
return install(args[0])
121+
elif len(args) == 2:
122+
return install(args[0], args[1])
123+
else:
124+
print_help()
108125
return 1
109-
return install(args[0])
110126
else:
111127
print('Unknown command')
112128
return 1

0 commit comments

Comments
 (0)