Skip to content

Commit 8280c4c

Browse files
committed
branch: streamline "attr_only" handling in validate_new_branchname()
The function takes a parameter "attr_only" (which is a name that is hard to reason about, which will be corrected soon) and skips some checks when it is set. Reorganize the conditionals to make it more obvious that some checks are never made when this parameter is set. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 111ef79 commit 8280c4c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

branch.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,25 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
181181
int validate_new_branchname(const char *name, struct strbuf *ref,
182182
int force, int attr_only)
183183
{
184+
const char *head;
185+
184186
if (strbuf_check_branch_ref(ref, name))
185187
die(_("'%s' is not a valid branch name."), name);
186188

187189
if (!ref_exists(ref->buf))
188190
return 0;
189-
else if (!force && !attr_only)
190-
die(_("A branch named '%s' already exists."), ref->buf + strlen("refs/heads/"));
191191

192-
if (!attr_only) {
193-
const char *head;
192+
if (attr_only)
193+
return 1;
194+
195+
if (!force)
196+
die(_("A branch named '%s' already exists."),
197+
ref->buf + strlen("refs/heads/"));
198+
199+
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
200+
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
201+
die(_("Cannot force update the current branch."));
194202

195-
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
196-
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
197-
die(_("Cannot force update the current branch."));
198-
}
199203
return 1;
200204
}
201205

0 commit comments

Comments
 (0)