Skip to content

Commit d18602f

Browse files
committed
Merge branch 'jk/branch-l-0-deprecation'
The "-l" option in "git branch -l" is an unfortunate short-hand for "--create-reflog", but many users, both old and new, somehow expect it to be something else, perhaps "--list". This step warns when "-l" is used as a short-hand for "--create-reflog" and warns about the future repurposing of the it when it is used. * jk/branch-l-0-deprecation: branch: deprecate "-l" option t: switch "branch -l" to "branch --create-reflog" t3200: unset core.logallrefupdates when testing reflog creation
2 parents d036d66 + 055930b commit d18602f

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
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
@@ -37,6 +37,7 @@ static const char * const builtin_branch_usage[] = {
3737

3838
static const char *head;
3939
static struct object_id head_oid;
40+
static int used_deprecated_reflog_option;
4041

4142
static int branch_use_color = -1;
4243
static char branch_colors[][COLOR_MAXLEN] = {
@@ -568,6 +569,14 @@ static int edit_branch_description(const char *branch_name)
568569
return 0;
569570
}
570571

572+
static int deprecated_reflog_option_cb(const struct option *opt,
573+
const char *arg, int unset)
574+
{
575+
used_deprecated_reflog_option = 1;
576+
*(int *)opt->value = !unset;
577+
return 0;
578+
}
579+
571580
int cmd_branch(int argc, const char **argv, const char *prefix)
572581
{
573582
int delete = 0, rename = 0, copy = 0, force = 0, list = 0;
@@ -610,7 +619,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
610619
OPT_BIT('c', "copy", &copy, N_("copy a branch and its reflog"), 1),
611620
OPT_BIT('C', NULL, &copy, N_("copy a branch, even if target exists"), 2),
612621
OPT_BOOL(0, "list", &list, N_("list branch names")),
613-
OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")),
622+
OPT_BOOL(0, "create-reflog", &reflog, N_("create the branch's reflog")),
623+
{
624+
OPTION_CALLBACK, 'l', NULL, &reflog, NULL,
625+
N_("deprecated synonym for --create-reflog"),
626+
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN,
627+
deprecated_reflog_option_cb
628+
},
614629
OPT_BOOL(0, "edit-description", &edit_description,
615630
N_("edit the description for the branch")),
616631
OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE),
@@ -683,6 +698,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
683698
if (list)
684699
setup_auto_pager("branch", 1);
685700

701+
if (used_deprecated_reflog_option && !list) {
702+
warning("the '-l' alias for '--create-reflog' is deprecated;");
703+
warning("it will be removed in a future version of Git");
704+
}
705+
686706
if (delete) {
687707
if (!argc)
688708
die(_("branch name required"));

t/t1410-reflog.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ test_expect_failure 'reflog with non-commit entries displays all entries' '
339339
'
340340

341341
test_expect_success 'reflog expire operates on symref not referrent' '
342-
git branch -l the_symref &&
343-
git branch -l referrent &&
342+
git branch --create-reflog the_symref &&
343+
git branch --create-reflog referrent &&
344344
git update-ref referrent HEAD &&
345345
git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
346346
test_when_finished "rm -f .git/refs/heads/referrent.lock" &&

t/t3200-branch.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ test_expect_success 'git branch HEAD should fail' '
4949
cat >expect <<EOF
5050
$ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
5151
EOF
52-
test_expect_success 'git branch -l d/e/f should create a branch and a log' '
52+
test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
5353
GIT_COMMITTER_DATE="2005-05-26 23:30" \
54-
git branch -l d/e/f &&
54+
git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
5555
test_path_is_file .git/refs/heads/d/e/f &&
5656
test_path_is_file .git/logs/refs/heads/d/e/f &&
5757
test_cmp expect .git/logs/refs/heads/d/e/f
@@ -82,21 +82,21 @@ test_expect_success 'git branch -m dumps usage' '
8282

8383
test_expect_success 'git branch -m m broken_symref should work' '
8484
test_when_finished "git branch -D broken_symref" &&
85-
git branch -l m &&
85+
git branch --create-reflog m &&
8686
git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
8787
git branch -m m broken_symref &&
8888
git reflog exists refs/heads/broken_symref &&
8989
test_must_fail git reflog exists refs/heads/i_am_broken
9090
'
9191

9292
test_expect_success 'git branch -m m m/m should work' '
93-
git branch -l m &&
93+
git branch --create-reflog m &&
9494
git branch -m m m/m &&
9595
git reflog exists refs/heads/m/m
9696
'
9797

9898
test_expect_success 'git branch -m n/n n should work' '
99-
git branch -l n/n &&
99+
git branch --create-reflog n/n &&
100100
git branch -m n/n n &&
101101
git reflog exists refs/heads/n
102102
'
@@ -378,9 +378,9 @@ mv .git/config-saved .git/config
378378
git config branch.s/s.dummy Hello
379379

380380
test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
381-
git branch -l s/s &&
381+
git branch --create-reflog s/s &&
382382
git reflog exists refs/heads/s/s &&
383-
git branch -l s/t &&
383+
git branch --create-reflog s/t &&
384384
git reflog exists refs/heads/s/t &&
385385
git branch -d s/t &&
386386
git branch -m s/s s &&
@@ -444,7 +444,7 @@ test_expect_success 'git branch --copy dumps usage' '
444444
'
445445

446446
test_expect_success 'git branch -c d e should work' '
447-
git branch -l d &&
447+
git branch --create-reflog d &&
448448
git reflog exists refs/heads/d &&
449449
git config branch.d.dummy Hello &&
450450
git branch -c d e &&
@@ -459,7 +459,7 @@ test_expect_success 'git branch -c d e should work' '
459459
'
460460

461461
test_expect_success 'git branch --copy is a synonym for -c' '
462-
git branch -l copy &&
462+
git branch --create-reflog copy &&
463463
git reflog exists refs/heads/copy &&
464464
git config branch.copy.dummy Hello &&
465465
git branch --copy copy copy-to &&
@@ -486,7 +486,7 @@ test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
486486
'
487487

488488
test_expect_success 'git branch -c f/f g/g should work' '
489-
git branch -l f/f &&
489+
git branch --create-reflog f/f &&
490490
git reflog exists refs/heads/f/f &&
491491
git config branch.f/f.dummy Hello &&
492492
git branch -c f/f g/g &&
@@ -497,7 +497,7 @@ test_expect_success 'git branch -c f/f g/g should work' '
497497
'
498498

499499
test_expect_success 'git branch -c m2 m2 should work' '
500-
git branch -l m2 &&
500+
git branch --create-reflog m2 &&
501501
git reflog exists refs/heads/m2 &&
502502
git config branch.m2.dummy Hello &&
503503
git branch -c m2 m2 &&
@@ -506,18 +506,18 @@ test_expect_success 'git branch -c m2 m2 should work' '
506506
'
507507

508508
test_expect_success 'git branch -c zz zz/zz should fail' '
509-
git branch -l zz &&
509+
git branch --create-reflog zz &&
510510
git reflog exists refs/heads/zz &&
511511
test_must_fail git branch -c zz zz/zz
512512
'
513513

514514
test_expect_success 'git branch -c b/b b should fail' '
515-
git branch -l b/b &&
515+
git branch --create-reflog b/b &&
516516
test_must_fail git branch -c b/b b
517517
'
518518

519519
test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
520-
git branch -l o/q &&
520+
git branch --create-reflog o/q &&
521521
git reflog exists refs/heads/o/q &&
522522
git reflog exists refs/heads/o/p &&
523523
git branch -C o/q o/p
@@ -570,10 +570,10 @@ test_expect_success 'git branch -C master5 master5 should work when master is ch
570570
'
571571

572572
test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
573-
git branch -l cd &&
573+
git branch --create-reflog cd &&
574574
git reflog exists refs/heads/cd &&
575575
git config branch.cd.dummy CD &&
576-
git branch -l ab &&
576+
git branch --create-reflog ab &&
577577
git reflog exists refs/heads/ab &&
578578
git config branch.ab.dummy AB &&
579579
git branch -C ab cd &&
@@ -685,7 +685,7 @@ test_expect_success 'renaming a symref is not allowed' '
685685
'
686686

687687
test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
688-
git branch -l u &&
688+
git branch --create-reflog u &&
689689
mv .git/logs/refs/heads/u real-u &&
690690
ln -s real-u .git/logs/refs/heads/u &&
691691
test_must_fail git branch -m u v

0 commit comments

Comments
 (0)