@@ -64,7 +64,7 @@ int install_branch_config(int flag, const char *local, const char *origin, const
6464 if (skip_prefix (remote , "refs/heads/" , & shortname )
6565 && !strcmp (local , shortname )
6666 && !origin ) {
67- warning (_ ("Not setting branch %s as its own upstream. " ),
67+ warning (_ ("not setting branch %s as its own upstream" ),
6868 local );
6969 return 0 ;
7070 }
@@ -116,7 +116,7 @@ int install_branch_config(int flag, const char *local, const char *origin, const
116116
117117out_err :
118118 strbuf_release (& key );
119- error (_ ("Unable to write upstream branch configuration" ));
119+ error (_ ("unable to write upstream branch configuration" ));
120120
121121 advise (_ (tracking_advice ),
122122 origin ? origin : "" ,
@@ -153,7 +153,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
153153 }
154154
155155 if (tracking .matches > 1 )
156- die (_ ("Not tracking: ambiguous information for ref %s" ),
156+ die (_ ("not tracking: ambiguous information for ref %s" ),
157157 orig_ref );
158158
159159 if (install_branch_config (config_flags , new_ref , tracking .remote ,
@@ -186,7 +186,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
186186int validate_branchname (const char * name , struct strbuf * ref )
187187{
188188 if (strbuf_check_branch_ref (ref , name ))
189- die (_ ("'%s' is not a valid branch name. " ), name );
189+ die (_ ("'%s' is not a valid branch name" ), name );
190190
191191 return ref_exists (ref -> buf );
192192}
@@ -199,18 +199,23 @@ int validate_branchname(const char *name, struct strbuf *ref)
199199 */
200200int validate_new_branchname (const char * name , struct strbuf * ref , int force )
201201{
202- const char * head ;
202+ struct worktree * * worktrees ;
203+ const struct worktree * wt ;
203204
204205 if (!validate_branchname (name , ref ))
205206 return 0 ;
206207
207208 if (!force )
208- die (_ ("A branch named '%s' already exists. " ),
209+ die (_ ("a branch named '%s' already exists" ),
209210 ref -> buf + strlen ("refs/heads/" ));
210211
211- head = resolve_ref_unsafe ("HEAD" , 0 , NULL , NULL );
212- if (!is_bare_repository () && head && !strcmp (head , ref -> buf ))
213- die (_ ("Cannot force update the current branch." ));
212+ worktrees = get_worktrees ();
213+ wt = find_shared_symref (worktrees , "HEAD" , ref -> buf );
214+ if (wt && !wt -> is_bare )
215+ die (_ ("cannot force update the branch '%s'"
216+ "checked out at '%s'" ),
217+ ref -> buf + strlen ("refs/heads/" ), wt -> path );
218+ free_worktrees (worktrees );
214219
215220 return 1 ;
216221}
@@ -230,7 +235,7 @@ static int validate_remote_tracking_branch(char *ref)
230235}
231236
232237static const char upstream_not_branch [] =
233- N_ ("Cannot setup tracking information; starting point '%s' is not a branch. " );
238+ N_ ("cannot set up tracking information; starting point '%s' is not a branch" );
234239static const char upstream_missing [] =
235240N_ ("the requested upstream branch '%s' does not exist" );
236241static const char upstream_advice [] =
@@ -278,7 +283,7 @@ void create_branch(struct repository *r,
278283 }
279284 die (_ (upstream_missing ), start_name );
280285 }
281- die (_ ("Not a valid object name: '%s'. " ), start_name );
286+ die (_ ("not a valid object name: '%s'" ), start_name );
282287 }
283288
284289 switch (dwim_ref (start_name , strlen (start_name ), & oid , & real_ref , 0 )) {
@@ -298,12 +303,12 @@ void create_branch(struct repository *r,
298303 }
299304 break ;
300305 default :
301- die (_ ("Ambiguous object name: '%s'. " ), start_name );
306+ die (_ ("ambiguous object name: '%s'" ), start_name );
302307 break ;
303308 }
304309
305310 if ((commit = lookup_commit_reference (r , & oid )) == NULL )
306- die (_ ("Not a valid branch point: '%s'. " ), start_name );
311+ die (_ ("not a valid branch point: '%s'" ), start_name );
307312 oidcpy (& oid , & commit -> object .oid );
308313
309314 if (reflog )
@@ -357,14 +362,16 @@ void remove_branch_state(struct repository *r, int verbose)
357362
358363void die_if_checked_out (const char * branch , int ignore_current_worktree )
359364{
365+ struct worktree * * worktrees = get_worktrees ();
360366 const struct worktree * wt ;
361367
362- wt = find_shared_symref ("HEAD" , branch );
363- if (!wt || (ignore_current_worktree && wt -> is_current ))
364- return ;
365- skip_prefix (branch , "refs/heads/" , & branch );
366- die (_ ("'%s' is already checked out at '%s'" ),
367- branch , wt -> path );
368+ wt = find_shared_symref (worktrees , "HEAD" , branch );
369+ if (wt && (!ignore_current_worktree || !wt -> is_current )) {
370+ skip_prefix (branch , "refs/heads/" , & branch );
371+ die (_ ("'%s' is already checked out at '%s'" ), branch , wt -> path );
372+ }
373+
374+ free_worktrees (worktrees );
368375}
369376
370377int replace_each_worktree_head_symref (const char * oldref , const char * newref ,
0 commit comments