@@ -64,7 +64,7 @@ int install_branch_config(int flag, const char *local, const char *origin, const
64
64
if (skip_prefix (remote , "refs/heads/" , & shortname )
65
65
&& !strcmp (local , shortname )
66
66
&& !origin ) {
67
- warning (_ ("Not setting branch %s as its own upstream. " ),
67
+ warning (_ ("not setting branch %s as its own upstream" ),
68
68
local );
69
69
return 0 ;
70
70
}
@@ -116,7 +116,7 @@ int install_branch_config(int flag, const char *local, const char *origin, const
116
116
117
117
out_err :
118
118
strbuf_release (& key );
119
- error (_ ("Unable to write upstream branch configuration" ));
119
+ error (_ ("unable to write upstream branch configuration" ));
120
120
121
121
advise (_ (tracking_advice ),
122
122
origin ? origin : "" ,
@@ -153,7 +153,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
153
153
}
154
154
155
155
if (tracking .matches > 1 )
156
- die (_ ("Not tracking: ambiguous information for ref %s" ),
156
+ die (_ ("not tracking: ambiguous information for ref %s" ),
157
157
orig_ref );
158
158
159
159
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)
186
186
int validate_branchname (const char * name , struct strbuf * ref )
187
187
{
188
188
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 );
190
190
191
191
return ref_exists (ref -> buf );
192
192
}
@@ -199,18 +199,23 @@ int validate_branchname(const char *name, struct strbuf *ref)
199
199
*/
200
200
int validate_new_branchname (const char * name , struct strbuf * ref , int force )
201
201
{
202
- const char * head ;
202
+ struct worktree * * worktrees ;
203
+ const struct worktree * wt ;
203
204
204
205
if (!validate_branchname (name , ref ))
205
206
return 0 ;
206
207
207
208
if (!force )
208
- die (_ ("A branch named '%s' already exists. " ),
209
+ die (_ ("a branch named '%s' already exists" ),
209
210
ref -> buf + strlen ("refs/heads/" ));
210
211
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 );
214
219
215
220
return 1 ;
216
221
}
@@ -230,7 +235,7 @@ static int validate_remote_tracking_branch(char *ref)
230
235
}
231
236
232
237
static 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" );
234
239
static const char upstream_missing [] =
235
240
N_ ("the requested upstream branch '%s' does not exist" );
236
241
static const char upstream_advice [] =
@@ -278,7 +283,7 @@ void create_branch(struct repository *r,
278
283
}
279
284
die (_ (upstream_missing ), start_name );
280
285
}
281
- die (_ ("Not a valid object name: '%s'. " ), start_name );
286
+ die (_ ("not a valid object name: '%s'" ), start_name );
282
287
}
283
288
284
289
switch (dwim_ref (start_name , strlen (start_name ), & oid , & real_ref , 0 )) {
@@ -298,12 +303,12 @@ void create_branch(struct repository *r,
298
303
}
299
304
break ;
300
305
default :
301
- die (_ ("Ambiguous object name: '%s'. " ), start_name );
306
+ die (_ ("ambiguous object name: '%s'" ), start_name );
302
307
break ;
303
308
}
304
309
305
310
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 );
307
312
oidcpy (& oid , & commit -> object .oid );
308
313
309
314
if (reflog )
@@ -357,14 +362,16 @@ void remove_branch_state(struct repository *r, int verbose)
357
362
358
363
void die_if_checked_out (const char * branch , int ignore_current_worktree )
359
364
{
365
+ struct worktree * * worktrees = get_worktrees ();
360
366
const struct worktree * wt ;
361
367
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 );
368
375
}
369
376
370
377
int replace_each_worktree_head_symref (const char * oldref , const char * newref ,
0 commit comments