@@ -18,6 +18,10 @@ def parser(subparsers):
18
18
branch_parser .add_argument (
19
19
'branch' , nargs = '?' ,
20
20
help = 'switch to branch (will be created if it doesn\' t exist yet)' )
21
+ branch_parser .add_argument (
22
+ 'divergent_point' , nargs = '?' ,
23
+ help = 'the commit from where to \' branch out\' (only relevant if a new '
24
+ 'branch is created; defaults to HEAD)' , default = 'HEAD' )
21
25
branch_parser .add_argument (
22
26
'-d' , '--delete' , nargs = '+' , help = 'delete branch(es)' , dest = 'delete_b' )
23
27
branch_parser .add_argument (
@@ -28,8 +32,8 @@ def parser(subparsers):
28
32
29
33
def main (args ):
30
34
if args .branch :
31
- exists , is_current , unused_tracks = branch_lib .status (args .branch )
32
- if exists and is_current :
35
+ b_st = branch_lib .status (args .branch )
36
+ if b_st . exists and b_st . is_current :
33
37
pprint .err (
34
38
'You are already in branch %s. No need to switch.' % args .branch )
35
39
pprint .err_exp ('to list existing branches do gl branch' )
@@ -47,11 +51,14 @@ def main(args):
47
51
'-- this will be implemented in the future)' )
48
52
return False
49
53
50
- if not exists :
51
- ret = branch_lib .create (args .branch )
54
+ if not b_st . exists :
55
+ ret = branch_lib .create (args .branch , dp = args . divergent_point )
52
56
if ret is branch_lib .INVALID_NAME :
53
57
pprint .err ('Invalid branch name' )
54
58
return False
59
+ elif ret == branch_lib .INVALID_DP :
60
+ pprint .msg ('Invalid divergent point {}' .format (args .divergent_point ))
61
+ return False
55
62
elif ret is branch_lib .SUCCESS :
56
63
pprint .msg ('Created new branch %s' % args .branch )
57
64
else :
@@ -77,11 +84,11 @@ def _do_list():
77
84
'use gl branch -su <upstream> to set an upstream for the current branch' )
78
85
pprint .exp ('* = current branch' )
79
86
pprint .blank ()
80
- for name , is_current , upstream , upstream_in_remote in branch_lib .status_all ():
87
+ for name , is_current , upstream , upstream_exists in branch_lib .status_all ():
81
88
current_str = '*' if is_current else ' '
82
89
upstream_str = ''
83
90
if upstream :
84
- np_str = ' --not present in remote yet' if not upstream_in_remote else ''
91
+ np_str = ' --not present in remote yet' if not upstream_exists else ''
85
92
upstream_str = '(upstream is %s%s)' % (upstream , np_str )
86
93
pprint .item ('%s %s %s' % (current_str , name , upstream_str ))
87
94
@@ -90,12 +97,12 @@ def _do_delete(delete_b):
90
97
errors_found = False
91
98
92
99
for b in delete_b :
93
- exists , is_current , unused_tracks = branch_lib .status (b )
94
- if not exists :
100
+ b_st = branch_lib .status (b )
101
+ if not b_st . exists :
95
102
pprint .err ('Can\' t remove non-existent branch %s' % b )
96
103
pprint .err_exp ('to list existing branches do gl branch' )
97
104
errors_found = True
98
- elif exists and is_current :
105
+ elif b_st . exists and b_st . is_current :
99
106
pprint .err ('Can\' t remove current branch %s' % b )
100
107
pprint .err_exp (
101
108
'use gl branch <b> to create or switch to another branch b and then '
@@ -115,11 +122,11 @@ def _do_set_upstream(upstream):
115
122
pprint .err (
116
123
'Invalid upstream branch. It must be in the format remote/branch' )
117
124
return True
118
- upstream_remote , upstream_branch = upstream .split ('/' )
119
125
120
- ret = branch_lib .set_upstream (upstream_remote , upstream_branch )
121
- errors_found = False
126
+ ret = branch_lib .set_upstream (upstream )
122
127
128
+ errors_found = False
129
+ upstream_remote , upstream_branch = upstream .split ('/' )
123
130
if ret is branch_lib .REMOTE_NOT_FOUND :
124
131
pprint .err ('Remote %s not found' % upstream_remote )
125
132
pprint .err_exp ('do gl remote show to list all available remotes' )
0 commit comments