Skip to content

Commit 055930b

Browse files
peffgitster
authored andcommitted
branch: deprecate "-l" option
The "-l" option is short for "--create-reflog". This has caused much confusion over the years. Most people expect it to work as "--list", because that would match the other "mode" options like -d/--delete and -m/--move, as well as the similar -l/--list option of git-tag. Adding to the confusion, using "-l" _appears_ to work as "--list" in some cases: $ git branch -l * master because the branch command defaults to listing (so even trying to specify --list in the command above is redundant). But that may bite the user later when they add a pattern, like: $ git branch -l foo which does not return an empty list, but in fact creates a new branch (with a reflog, naturally) called "foo". It's also probably quite uncommon for people to actually use "-l" to create a reflog. Since 0bee591 (Enable reflogs by default in any repository with a working directory., 2006-12-14), this is the default in non-bare repositories. So it's rather unfortunate that the feature squats on the short-and-sweet "-l" (which was only added in 3a4b3f2 (Create/delete branch ref logs., 2006-05-19), meaning there were only 7 months where it was actually useful). Let's deprecate "-l" in hopes of eventually re-purposing it to "--list". Note that we issue the warning only when we're not in list mode. This means that people for whom it works as a happy accident, namely: $ git branch -l master won't see the warning at all. And when we eventually switch to it meaning "--list", that will just continue to work. We do the issue the warning for these important cases: - when we are actually creating a branch, in case the user really did mean it as "--create-reflog" - when we are in some _other_ mode, like deletion. There the "-l" is a noop for now, but it will eventually conflict with any other mode request, and the user should be told that this is changing. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7687f19 commit 055930b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Documentation/git-branch.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ OPTIONS
9191
-D::
9292
Shortcut for `--delete --force`.
9393

94-
-l::
9594
--create-reflog::
9695
Create the branch's reflog. This activates recording of
9796
all changes made to the branch ref, enabling use of date
@@ -101,6 +100,8 @@ OPTIONS
101100
The negated form `--no-create-reflog` only overrides an earlier
102101
`--create-reflog`, but currently does not negate the setting of
103102
`core.logAllRefUpdates`.
103+
+
104+
The `-l` option is a deprecated synonym for `--create-reflog`.
104105

105106
-f::
106107
--force::

builtin/branch.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const char * const builtin_branch_usage[] = {
3636

3737
static const char *head;
3838
static struct object_id head_oid;
39+
static int used_deprecated_reflog_option;
3940

4041
static int branch_use_color = -1;
4142
static char branch_colors[][COLOR_MAXLEN] = {
@@ -573,6 +574,14 @@ static int edit_branch_description(const char *branch_name)
573574
return 0;
574575
}
575576

577+
static int deprecated_reflog_option_cb(const struct option *opt,
578+
const char *arg, int unset)
579+
{
580+
used_deprecated_reflog_option = 1;
581+
*(int *)opt->value = !unset;
582+
return 0;
583+
}
584+
576585
int cmd_branch(int argc, const char **argv, const char *prefix)
577586
{
578587
int delete = 0, rename = 0, copy = 0, force = 0, list = 0;
@@ -615,7 +624,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
615624
OPT_BIT('c', "copy", &copy, N_("copy a branch and its reflog"), 1),
616625
OPT_BIT('C', NULL, &copy, N_("copy a branch, even if target exists"), 2),
617626
OPT_BOOL(0, "list", &list, N_("list branch names")),
618-
OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")),
627+
OPT_BOOL(0, "create-reflog", &reflog, N_("create the branch's reflog")),
628+
{
629+
OPTION_CALLBACK, 'l', NULL, &reflog, NULL,
630+
N_("deprecated synonym for --create-reflog"),
631+
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN,
632+
deprecated_reflog_option_cb
633+
},
619634
OPT_BOOL(0, "edit-description", &edit_description,
620635
N_("edit the description for the branch")),
621636
OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE),
@@ -688,6 +703,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
688703
if (list)
689704
setup_auto_pager("branch", 1);
690705

706+
if (used_deprecated_reflog_option && !list) {
707+
warning("the '-l' alias for '--create-reflog' is deprecated;");
708+
warning("it will be removed in a future version of Git");
709+
}
710+
691711
if (delete) {
692712
if (!argc)
693713
die(_("branch name required"));

0 commit comments

Comments
 (0)