4 * Copyright (c) 2006 Kristian Høgsberg <krh@redhat.com>
5 * Based on git-branch.sh by Junio C Hamano.
14 #include "parse-options.h"
18 #include "tree-walk.h"
19 #include "unpack-trees.h"
21 static const char * const builtin_branch_usage
[] = {
22 "git branch [options] [-r | -a] [--merged | --no-merged]",
23 "git branch [options] [-l] [-f] <branchname> [<start-point>]",
24 "git branch [options] [-r] (-d | -D) <branchname>",
25 "git branch [options] (-m | -M) [<oldbranch>] <newbranch>",
29 #define REF_LOCAL_BRANCH 0x01
30 #define REF_REMOTE_BRANCH 0x02
32 static const char *head
;
33 static unsigned char head_sha1
[20];
35 static int branch_use_color
= -1;
36 static char branch_colors
[][COLOR_MAXLEN
] = {
38 GIT_COLOR_NORMAL
, /* PLAIN */
39 GIT_COLOR_RED
, /* REMOTE */
40 GIT_COLOR_NORMAL
, /* LOCAL */
41 GIT_COLOR_GREEN
, /* CURRENT */
44 BRANCH_COLOR_RESET
= 0,
45 BRANCH_COLOR_PLAIN
= 1,
46 BRANCH_COLOR_REMOTE
= 2,
47 BRANCH_COLOR_LOCAL
= 3,
48 BRANCH_COLOR_CURRENT
= 4,
51 static enum merge_filter
{
56 static unsigned char merge_filter_ref
[20];
58 static int parse_branch_color_slot(const char *var
, int ofs
)
60 if (!strcasecmp(var
+ofs
, "plain"))
61 return BRANCH_COLOR_PLAIN
;
62 if (!strcasecmp(var
+ofs
, "reset"))
63 return BRANCH_COLOR_RESET
;
64 if (!strcasecmp(var
+ofs
, "remote"))
65 return BRANCH_COLOR_REMOTE
;
66 if (!strcasecmp(var
+ofs
, "local"))
67 return BRANCH_COLOR_LOCAL
;
68 if (!strcasecmp(var
+ofs
, "current"))
69 return BRANCH_COLOR_CURRENT
;
73 static int git_branch_config(const char *var
, const char *value
, void *cb
)
75 if (!strcmp(var
, "color.branch")) {
76 branch_use_color
= git_config_colorbool(var
, value
, -1);
79 if (!prefixcmp(var
, "color.branch.")) {
80 int slot
= parse_branch_color_slot(var
, 13);
84 return config_error_nonbool(var
);
85 color_parse(value
, var
, branch_colors
[slot
]);
88 return git_color_default_config(var
, value
, cb
);
91 static const char *branch_get_color(enum color_branch ix
)
93 if (branch_use_color
> 0)
94 return branch_colors
[ix
];
98 static int branch_merged(int kind
, const char *name
,
99 struct commit
*rev
, struct commit
*head_rev
)
102 * This checks whether the merge bases of branch and HEAD (or
103 * the other branch this branch builds upon) contains the
104 * branch, which means that the branch has already been merged
105 * safely to HEAD (or the other branch).
107 struct commit
*reference_rev
= NULL
;
108 const char *reference_name
= NULL
;
111 if (kind
== REF_LOCAL_BRANCH
) {
112 struct branch
*branch
= branch_get(name
);
113 unsigned char sha1
[20];
118 branch
->merge
[0]->dst
&&
120 resolve_ref(branch
->merge
[0]->dst
, sha1
, 1, NULL
)) != NULL
)
121 reference_rev
= lookup_commit_reference(sha1
);
124 reference_rev
= head_rev
;
126 merged
= in_merge_bases(rev
, &reference_rev
, 1);
129 * After the safety valve is fully redefined to "check with
130 * upstream, if any, otherwise with HEAD", we should just
131 * return the result of the in_merge_bases() above without
132 * any of the following code, but during the transition period,
133 * a gentle reminder is in order.
135 if ((head_rev
!= reference_rev
) &&
136 in_merge_bases(rev
, &head_rev
, 1) != merged
) {
138 warning("deleting branch '%s' that has been merged to\n"
139 " '%s', but it is not yet merged to HEAD.",
140 name
, reference_name
);
142 warning("not deleting branch '%s' that is not yet merged to\n"
143 " '%s', even though it is merged to HEAD.",
144 name
, reference_name
);
149 static int delete_branches(int argc
, const char **argv
, int force
, int kinds
)
151 struct commit
*rev
, *head_rev
= NULL
;
152 unsigned char sha1
[20];
154 const char *fmt
, *remote
;
157 struct strbuf bname
= STRBUF_INIT
;
160 case REF_REMOTE_BRANCH
:
161 fmt
= "refs/remotes/%s";
165 case REF_LOCAL_BRANCH
:
166 fmt
= "refs/heads/%s";
170 die("cannot use -a with -d");
174 head_rev
= lookup_commit_reference(head_sha1
);
176 die("Couldn't look up commit object for HEAD");
178 for (i
= 0; i
< argc
; i
++, strbuf_release(&bname
)) {
179 strbuf_branchname(&bname
, argv
[i
]);
180 if (kinds
== REF_LOCAL_BRANCH
&& !strcmp(head
, bname
.buf
)) {
181 error("Cannot delete the branch '%s' "
182 "which you are currently on.", bname
.buf
);
189 name
= xstrdup(mkpath(fmt
, bname
.buf
));
190 if (!resolve_ref(name
, sha1
, 1, NULL
)) {
191 error("%sbranch '%s' not found.",
197 rev
= lookup_commit_reference(sha1
);
199 error("Couldn't look up commit object for '%s'", name
);
204 if (!force
&& !branch_merged(kinds
, bname
.buf
, rev
, head_rev
)) {
205 error("The branch '%s' is not fully merged.\n"
206 "If you are sure you want to delete it, "
207 "run 'git branch -D %s'.", bname
.buf
, bname
.buf
);
212 if (delete_ref(name
, sha1
, 0)) {
213 error("Error deleting %sbranch '%s'", remote
,
217 struct strbuf buf
= STRBUF_INIT
;
218 printf("Deleted %sbranch %s (was %s).\n", remote
,
220 find_unique_abbrev(sha1
, DEFAULT_ABBREV
));
221 strbuf_addf(&buf
, "branch.%s", bname
.buf
);
222 if (git_config_rename_section(buf
.buf
, NULL
) < 0)
223 warning("Update of config-file failed");
224 strbuf_release(&buf
);
236 unsigned int kind
, len
;
237 struct commit
*commit
;
241 struct rev_info revs
;
242 int index
, alloc
, maxwidth
, verbose
, abbrev
;
243 struct ref_item
*list
;
244 struct commit_list
*with_commit
;
248 static char *resolve_symref(const char *src
, const char *prefix
)
250 unsigned char sha1
[20];
252 const char *dst
, *cp
;
254 dst
= resolve_ref(src
, sha1
, 0, &flag
);
255 if (!(dst
&& (flag
& REF_ISSYMREF
)))
257 if (prefix
&& (cp
= skip_prefix(dst
, prefix
)))
262 static int append_ref(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
)
264 struct ref_list
*ref_list
= (struct ref_list
*)(cb_data
);
265 struct ref_item
*newitem
;
266 struct commit
*commit
;
268 const char *prefix
, *orig_refname
= refname
;
275 { REF_LOCAL_BRANCH
, "refs/heads/", 11 },
276 { REF_REMOTE_BRANCH
, "refs/remotes/", 13 },
280 for (i
= 0; i
< ARRAY_SIZE(ref_kind
); i
++) {
281 prefix
= ref_kind
[i
].prefix
;
282 if (strncmp(refname
, prefix
, ref_kind
[i
].pfxlen
))
284 kind
= ref_kind
[i
].kind
;
285 refname
+= ref_kind
[i
].pfxlen
;
288 if (ARRAY_SIZE(ref_kind
) <= i
)
291 /* Don't add types the caller doesn't want */
292 if ((kind
& ref_list
->kinds
) == 0)
296 if (ref_list
->verbose
|| ref_list
->with_commit
|| merge_filter
!= NO_FILTER
) {
297 commit
= lookup_commit_reference_gently(sha1
, 1);
299 return error("branch '%s' does not point at a commit", refname
);
301 /* Filter with with_commit if specified */
302 if (!is_descendant_of(commit
, ref_list
->with_commit
))
305 if (merge_filter
!= NO_FILTER
)
306 add_pending_object(&ref_list
->revs
,
307 (struct object
*)commit
, refname
);
311 if (ref_list
->index
>= ref_list
->alloc
) {
312 ref_list
->alloc
= alloc_nr(ref_list
->alloc
);
313 ref_list
->list
= xrealloc(ref_list
->list
,
314 ref_list
->alloc
* sizeof(struct ref_item
));
317 /* Record the new item */
318 newitem
= &(ref_list
->list
[ref_list
->index
++]);
319 newitem
->name
= xstrdup(refname
);
320 newitem
->kind
= kind
;
321 newitem
->commit
= commit
;
322 newitem
->len
= strlen(refname
);
323 newitem
->dest
= resolve_symref(orig_refname
, prefix
);
324 /* adjust for "remotes/" */
325 if (newitem
->kind
== REF_REMOTE_BRANCH
&&
326 ref_list
->kinds
!= REF_REMOTE_BRANCH
)
328 if (newitem
->len
> ref_list
->maxwidth
)
329 ref_list
->maxwidth
= newitem
->len
;
334 static void free_ref_list(struct ref_list
*ref_list
)
338 for (i
= 0; i
< ref_list
->index
; i
++) {
339 free(ref_list
->list
[i
].name
);
340 free(ref_list
->list
[i
].dest
);
342 free(ref_list
->list
);
345 static int ref_cmp(const void *r1
, const void *r2
)
347 struct ref_item
*c1
= (struct ref_item
*)(r1
);
348 struct ref_item
*c2
= (struct ref_item
*)(r2
);
350 if (c1
->kind
!= c2
->kind
)
351 return c1
->kind
- c2
->kind
;
352 return strcmp(c1
->name
, c2
->name
);
355 static void fill_tracking_info(struct strbuf
*stat
, const char *branch_name
,
356 int show_upstream_ref
)
359 struct branch
*branch
= branch_get(branch_name
);
361 if (!stat_tracking_info(branch
, &ours
, &theirs
)) {
362 if (branch
&& branch
->merge
&& branch
->merge
[0]->dst
&&
364 strbuf_addf(stat
, "[%s] ",
365 shorten_unambiguous_ref(branch
->merge
[0]->dst
, 0));
369 strbuf_addch(stat
, '[');
370 if (show_upstream_ref
)
371 strbuf_addf(stat
, "%s: ",
372 shorten_unambiguous_ref(branch
->merge
[0]->dst
, 0));
374 strbuf_addf(stat
, "behind %d] ", theirs
);
376 strbuf_addf(stat
, "ahead %d] ", ours
);
378 strbuf_addf(stat
, "ahead %d, behind %d] ", ours
, theirs
);
381 static int matches_merge_filter(struct commit
*commit
)
385 if (merge_filter
== NO_FILTER
)
388 is_merged
= !!(commit
->object
.flags
& UNINTERESTING
);
389 return (is_merged
== (merge_filter
== SHOW_MERGED
));
392 static void print_ref_item(struct ref_item
*item
, int maxwidth
, int verbose
,
393 int abbrev
, int current
, char *prefix
)
397 struct commit
*commit
= item
->commit
;
398 struct strbuf out
= STRBUF_INIT
, name
= STRBUF_INIT
;
400 if (!matches_merge_filter(commit
))
403 switch (item
->kind
) {
404 case REF_LOCAL_BRANCH
:
405 color
= BRANCH_COLOR_LOCAL
;
407 case REF_REMOTE_BRANCH
:
408 color
= BRANCH_COLOR_REMOTE
;
411 color
= BRANCH_COLOR_PLAIN
;
418 color
= BRANCH_COLOR_CURRENT
;
421 strbuf_addf(&name
, "%s%s", prefix
, item
->name
);
423 strbuf_addf(&out
, "%c %s%-*s%s", c
, branch_get_color(color
),
425 branch_get_color(BRANCH_COLOR_RESET
));
427 strbuf_addf(&out
, "%c %s%s%s", c
, branch_get_color(color
),
428 name
.buf
, branch_get_color(BRANCH_COLOR_RESET
));
431 strbuf_addf(&out
, " -> %s", item
->dest
);
433 struct strbuf subject
= STRBUF_INIT
, stat
= STRBUF_INIT
;
434 const char *sub
= " **** invalid ref ****";
436 commit
= item
->commit
;
437 if (commit
&& !parse_commit(commit
)) {
438 struct pretty_print_context ctx
= {0};
439 pretty_print_commit(CMIT_FMT_ONELINE
, commit
,
444 if (item
->kind
== REF_LOCAL_BRANCH
)
445 fill_tracking_info(&stat
, item
->name
, verbose
> 1);
447 strbuf_addf(&out
, " %s %s%s",
448 find_unique_abbrev(item
->commit
->object
.sha1
, abbrev
),
450 strbuf_release(&stat
);
451 strbuf_release(&subject
);
453 printf("%s\n", out
.buf
);
454 strbuf_release(&name
);
455 strbuf_release(&out
);
458 static int calc_maxwidth(struct ref_list
*refs
)
461 for (i
= 0; i
< refs
->index
; i
++) {
462 if (!matches_merge_filter(refs
->list
[i
].commit
))
464 if (refs
->list
[i
].len
> w
)
465 w
= refs
->list
[i
].len
;
471 static void show_detached(struct ref_list
*ref_list
)
473 struct commit
*head_commit
= lookup_commit_reference_gently(head_sha1
, 1);
475 if (head_commit
&& is_descendant_of(head_commit
, ref_list
->with_commit
)) {
476 struct ref_item item
;
477 item
.name
= xstrdup("(no branch)");
478 item
.len
= strlen(item
.name
);
479 item
.kind
= REF_LOCAL_BRANCH
;
481 item
.commit
= head_commit
;
482 if (item
.len
> ref_list
->maxwidth
)
483 ref_list
->maxwidth
= item
.len
;
484 print_ref_item(&item
, ref_list
->maxwidth
, ref_list
->verbose
, ref_list
->abbrev
, 1, "");
489 static void print_ref_list(int kinds
, int detached
, int verbose
, int abbrev
, struct commit_list
*with_commit
)
492 struct ref_list ref_list
;
494 memset(&ref_list
, 0, sizeof(ref_list
));
495 ref_list
.kinds
= kinds
;
496 ref_list
.verbose
= verbose
;
497 ref_list
.abbrev
= abbrev
;
498 ref_list
.with_commit
= with_commit
;
499 if (merge_filter
!= NO_FILTER
)
500 init_revisions(&ref_list
.revs
, NULL
);
501 for_each_rawref(append_ref
, &ref_list
);
502 if (merge_filter
!= NO_FILTER
) {
503 struct commit
*filter
;
504 filter
= lookup_commit_reference_gently(merge_filter_ref
, 0);
505 filter
->object
.flags
|= UNINTERESTING
;
506 add_pending_object(&ref_list
.revs
,
507 (struct object
*) filter
, "");
508 ref_list
.revs
.limited
= 1;
509 prepare_revision_walk(&ref_list
.revs
);
511 ref_list
.maxwidth
= calc_maxwidth(&ref_list
);
514 qsort(ref_list
.list
, ref_list
.index
, sizeof(struct ref_item
), ref_cmp
);
516 detached
= (detached
&& (kinds
& REF_LOCAL_BRANCH
));
518 show_detached(&ref_list
);
520 for (i
= 0; i
< ref_list
.index
; i
++) {
521 int current
= !detached
&&
522 (ref_list
.list
[i
].kind
== REF_LOCAL_BRANCH
) &&
523 !strcmp(ref_list
.list
[i
].name
, head
);
524 char *prefix
= (kinds
!= REF_REMOTE_BRANCH
&&
525 ref_list
.list
[i
].kind
== REF_REMOTE_BRANCH
)
527 print_ref_item(&ref_list
.list
[i
], ref_list
.maxwidth
, verbose
,
528 abbrev
, current
, prefix
);
531 free_ref_list(&ref_list
);
534 static void rename_branch(const char *oldname
, const char *newname
, int force
)
536 struct strbuf oldref
= STRBUF_INIT
, newref
= STRBUF_INIT
, logmsg
= STRBUF_INIT
;
537 unsigned char sha1
[20];
538 struct strbuf oldsection
= STRBUF_INIT
, newsection
= STRBUF_INIT
;
542 die("cannot rename the current branch while not on any.");
544 if (strbuf_check_branch_ref(&oldref
, oldname
)) {
546 * Bad name --- this could be an attempt to rename a
547 * ref that we used to allow to be created by accident.
549 if (resolve_ref(oldref
.buf
, sha1
, 1, NULL
))
552 die("Invalid branch name: '%s'", oldname
);
555 if (strbuf_check_branch_ref(&newref
, newname
))
556 die("Invalid branch name: '%s'", newname
);
558 if (resolve_ref(newref
.buf
, sha1
, 1, NULL
) && !force
)
559 die("A branch named '%s' already exists.", newref
.buf
+ 11);
561 strbuf_addf(&logmsg
, "Branch: renamed %s to %s",
562 oldref
.buf
, newref
.buf
);
564 if (rename_ref(oldref
.buf
, newref
.buf
, logmsg
.buf
))
565 die("Branch rename failed");
566 strbuf_release(&logmsg
);
569 warning("Renamed a misnamed branch '%s' away", oldref
.buf
+ 11);
571 /* no need to pass logmsg here as HEAD didn't really move */
572 if (!strcmp(oldname
, head
) && create_symref("HEAD", newref
.buf
, NULL
))
573 die("Branch renamed to %s, but HEAD is not updated!", newname
);
575 strbuf_addf(&oldsection
, "branch.%s", oldref
.buf
+ 11);
576 strbuf_release(&oldref
);
577 strbuf_addf(&newsection
, "branch.%s", newref
.buf
+ 11);
578 strbuf_release(&newref
);
579 if (git_config_rename_section(oldsection
.buf
, newsection
.buf
) < 0)
580 die("Branch is renamed, but update of config-file failed");
581 strbuf_release(&oldsection
);
582 strbuf_release(&newsection
);
585 static struct lock_file lockfile
;
587 /* This function free()s path */
588 static int create_new_workdir(char *path
, const char *branch_name
)
590 static const char *links
[] = {
591 "config", "refs", "logs/refs", "objects", "info", "hooks",
592 "packed-refs", "remotes", "rr-cache", NULL
594 const char *git_dir
= get_git_dir(), *absolute
;
596 unsigned char sha1
[20];
598 struct object
*object
;
599 struct unpack_trees_options opts
;
600 struct tree_desc tree_desc
;
604 /* make sure that GIT_DIR is an absolute path */
605 if ((absolute
= make_absolute_path(git_dir
)) != git_dir
&&
606 set_git_dir(absolute
))
609 return error("New workdir not possible without symlinks");
610 if (!lstat(git_path("config"), &st
) && S_ISLNK(st
.st_mode
))
611 return error("Cannot create a workdir from a workdir");
612 if (safe_create_leading_directories(path
) ||
613 mkdir(path
, 0777) || chdir(path
))
614 return error("Could not create '%s'", path
);
615 if (mkdir(DEFAULT_GIT_DIR_ENVIRONMENT
, 0777) ||
616 chdir(DEFAULT_GIT_DIR_ENVIRONMENT
) ||
618 return error("Could not set up '%s/%s'",
619 path
, DEFAULT_GIT_DIR_ENVIRONMENT
);
620 for (i
= 0; links
[i
]; i
++)
621 if (symlink(git_path("%s", links
[i
]), links
[i
]))
622 return error("Could not link '%s'", links
[i
]);
623 if (chdir("..") || set_git_dir(DEFAULT_GIT_DIR_ENVIRONMENT
))
624 return error("Error setting up new workdir");
625 fd
= hold_locked_index(&lockfile
, 1);
627 return error("Could not lock index");
628 if (dwim_ref(branch_name
, strlen(branch_name
), sha1
, &ref
) != 1 ||
629 create_symref("HEAD", ref
, "new workdir") ||
630 !(object
= parse_object(sha1
)) ||
631 object
->type
!= OBJ_COMMIT
)
632 return error("Could not checkout HEAD");
635 tree
= ((struct commit
*)object
)->tree
;
637 init_tree_desc(&tree_desc
, tree
->buffer
, tree
->size
);
639 memset(&opts
, 0, sizeof(opts
));
643 opts
.fn
= oneway_merge
;
644 opts
.src_index
= &the_index
;
645 opts
.dst_index
= &the_index
;
646 return unpack_trees(1, &tree_desc
, &opts
) ||
647 write_cache(fd
, active_cache
, active_nr
) ||
648 commit_locked_index(&lockfile
);
651 static int opt_parse_merge_filter(const struct option
*opt
, const char *arg
, int unset
)
653 merge_filter
= ((opt
->long_name
[0] == 'n')
657 merge_filter
= SHOW_NOT_MERGED
; /* b/c for --no-merged */
660 if (get_sha1(arg
, merge_filter_ref
))
661 die("malformed object name %s", arg
);
665 int cmd_branch(int argc
, const char **argv
, const char *prefix
)
667 int delete = 0, rename
= 0, force_create
= 0;
668 int verbose
= 0, abbrev
= DEFAULT_ABBREV
, detached
= 0;
670 enum branch_track track
;
671 int kinds
= REF_LOCAL_BRANCH
;
672 struct commit_list
*with_commit
= NULL
;
673 char *new_workdir
= NULL
;
675 struct option options
[] = {
676 OPT_GROUP("Generic options"),
677 OPT__VERBOSE(&verbose
),
678 OPT_SET_INT('t', "track", &track
, "set up tracking mode (see git-pull(1))",
679 BRANCH_TRACK_EXPLICIT
),
680 OPT_SET_INT( 0, "set-upstream", &track
, "change upstream info",
681 BRANCH_TRACK_OVERRIDE
),
682 OPT_BOOLEAN( 0 , "color", &branch_use_color
, "use colored output"),
683 OPT_SET_INT('r', NULL
, &kinds
, "act on remote-tracking branches",
686 OPTION_CALLBACK
, 0, "contains", &with_commit
, "commit",
687 "print only branches that contain the commit",
688 PARSE_OPT_LASTARG_DEFAULT
,
689 parse_opt_with_commit
, (intptr_t)"HEAD",
692 OPTION_CALLBACK
, 0, "with", &with_commit
, "commit",
693 "print only branches that contain the commit",
694 PARSE_OPT_HIDDEN
| PARSE_OPT_LASTARG_DEFAULT
,
695 parse_opt_with_commit
, (intptr_t) "HEAD",
697 OPT__ABBREV(&abbrev
),
699 OPT_GROUP("Specific git-branch actions:"),
700 OPT_SET_INT('a', NULL
, &kinds
, "list both remote-tracking and local branches",
701 REF_REMOTE_BRANCH
| REF_LOCAL_BRANCH
),
702 OPT_BIT('d', NULL
, &delete, "delete fully merged branch", 1),
703 OPT_BIT('D', NULL
, &delete, "delete branch (even if not merged)", 2),
704 OPT_BIT('m', NULL
, &rename
, "move/rename a branch and its reflog", 1),
705 OPT_BIT('M', NULL
, &rename
, "move/rename a branch, even if target exists", 2),
706 OPT_BOOLEAN('l', NULL
, &reflog
, "create the branch's reflog"),
707 OPT_BOOLEAN('f', "force", &force_create
, "force creation (when already exists)"),
709 OPTION_CALLBACK
, 0, "no-merged", &merge_filter_ref
,
710 "commit", "print only not merged branches",
711 PARSE_OPT_LASTARG_DEFAULT
| PARSE_OPT_NONEG
,
712 opt_parse_merge_filter
, (intptr_t) "HEAD",
715 OPTION_CALLBACK
, 0, "merged", &merge_filter_ref
,
716 "commit", "print only merged branches",
717 PARSE_OPT_LASTARG_DEFAULT
| PARSE_OPT_NONEG
,
718 opt_parse_merge_filter
, (intptr_t) "HEAD",
720 OPT_STRING('n', "new-workdir", &new_workdir
, "dir", "create a new working directory for the created branch"),
724 git_config(git_branch_config
, NULL
);
726 if (branch_use_color
== -1)
727 branch_use_color
= git_use_color_default
;
729 track
= git_branch_track
;
731 head
= resolve_ref("HEAD", head_sha1
, 0, NULL
);
733 die("Failed to resolve HEAD as a valid ref.");
734 head
= xstrdup(head
);
735 if (!strcmp(head
, "HEAD")) {
738 if (prefixcmp(head
, "refs/heads/"))
739 die("HEAD not found below refs/heads!");
742 hashcpy(merge_filter_ref
, head_sha1
);
744 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_branch_usage
,
746 if (!!delete + !!rename
+ !!force_create
> 1 ||
747 (new_workdir
&& (delete || rename
)))
748 usage_with_options(builtin_branch_usage
, options
);
751 return delete_branches(argc
, argv
, delete > 1, kinds
);
753 print_ref_list(kinds
, detached
, verbose
, abbrev
, with_commit
);
754 else if (rename
&& (argc
== 1))
755 rename_branch(head
, argv
[0], rename
> 1);
756 else if (rename
&& (argc
== 2))
757 rename_branch(argv
[0], argv
[1], rename
> 1);
758 else if (argc
<= 2) {
759 if (kinds
!= REF_LOCAL_BRANCH
)
760 die("-a and -r options to 'git branch' do not make sense with a branch name");
761 create_branch(head
, argv
[0], (argc
== 2) ? argv
[1] : head
,
762 force_create
, reflog
, track
);
764 return create_new_workdir(new_workdir
, argv
[0]);
766 usage_with_options(builtin_branch_usage
, options
);