@@ -135,23 +135,25 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
135135 return 0 ;
136136}
137137
138- int validate_new_branchname (const char * name , struct strbuf * ref , int force )
138+ int validate_new_branchname (const char * name , struct strbuf * ref ,
139+ int force , int attr_only )
139140{
140- const char * head ;
141- unsigned char sha1 [20 ];
142-
143141 if (strbuf_check_branch_ref (ref , name ))
144142 die ("'%s' is not a valid branch name." , name );
145143
146144 if (!ref_exists (ref -> buf ))
147145 return 0 ;
148- else if (!force )
146+ else if (!force && ! attr_only )
149147 die ("A branch named '%s' already exists." , ref -> buf + strlen ("refs/heads/" ));
150148
151- head = resolve_ref ( "HEAD" , sha1 , 0 , NULL );
152- if (! is_bare_repository () && head && ! strcmp ( head , ref -> buf ))
153- die ( "Cannot force update the current branch." ) ;
149+ if (! attr_only ) {
150+ const char * head ;
151+ unsigned char sha1 [ 20 ] ;
154152
153+ head = resolve_ref ("HEAD" , sha1 , 0 , NULL );
154+ if (!is_bare_repository () && head && !strcmp (head , ref -> buf ))
155+ die ("Cannot force update the current branch." );
156+ }
155157 return 1 ;
156158}
157159
@@ -171,7 +173,8 @@ void create_branch(const char *head,
171173 if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE )
172174 explicit_tracking = 1 ;
173175
174- if (validate_new_branchname (name , & ref , force || track == BRANCH_TRACK_OVERRIDE )) {
176+ if (validate_new_branchname (name , & ref , force ,
177+ track == BRANCH_TRACK_OVERRIDE )) {
175178 if (!force )
176179 dont_change_ref = 1 ;
177180 else
0 commit comments