@matheusbsbs / matheus-bagliano / commits / 1dacfbcf13
Fork 0

branch -h: show usage even in an invalid repository

There is no need for "git branch -h" to try to access a repository. In the spirit of v1.6.6-rc0~34^2~3 (Let 'git <command> -h' show usage without a git dir, 2009-11-09). This brings git one step closer to passing the following (automatically verifiable) test: Before any repository access (aside from git_config()), a function from the setup_git_directory_* family has been run and thus one step closer to being able to use an automatic repository access checker. [jn: simplified; new commit message, test] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Oct 22, 2010 at 01:42 UTC 1dacfbcf13693dad508095735a95bc4b12382c57
2 files changed +14
builtin/branch.c
+3
@@ -667,6 +667,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
667 OPT_END(),
668 };
669
670 + if (argc == 2 && !strcmp(argv[1], "-h"))
671 + usage_with_options(builtin_branch_usage, options);
672 +
673 git_config(git_branch_config, NULL);
674
675 if (branch_use_color == -1)
t/t3200-branch.sh
+11
@@ -26,6 +26,17 @@ test_expect_success \
26 ! test -f .git/refs/heads/--help
27 '
28
29 +test_expect_success 'branch -h in broken repository' '
30 + mkdir broken &&
31 + (
32 + cd broken &&
33 + git init &&
34 + >.git/refs/heads/master &&
35 + test_expect_code 129 git branch -h >usage 2>&1
36 + ) &&
37 + grep "[Uu]sage" broken/usage
38 +'
39 +
40 test_expect_success \
41 'git branch abc should create a branch' \
42 'git branch abc && test -f .git/refs/heads/abc'