@matheusbsbs / matheus-bagliano / commits / cbb3167ef8
Fork 0

ls-files -h: show usage even with corrupt index

Part of a campaign to avoid git <command> -h being distracted by access to the repository. A caller hoping to use "git ls-files" with an alternate index as part of a repair operation may well use "git ls-files -h" to show usage while planning it out. [jn: with rewritten log message and tests] 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:48 UTC cbb3167ef8b73109ed5c5e54aa1915d9c50f83d5
2 files changed +42
builtin/ls-files.c
+3
@@ -530,6 +530,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
530 OPT_END()
531 };
532
533 + if (argc == 2 && !strcmp(argv[1], "-h"))
534 + usage_with_options(ls_files_usage, builtin_ls_files_options);
535 +
536 memset(&dir, 0, sizeof(dir));
537 prefix = cmd_prefix;
538 if (prefix)
t/t3004-ls-files-basic.sh new
+39
@@ -0,0 +1,39 @@
1 +#!/bin/sh
2 +
3 +test_description='basic ls-files tests
4 +
5 +This test runs git ls-files with various unusual or malformed
6 +command-line arguments.
7 +'
8 +
9 +. ./test-lib.sh
10 +
11 +>empty
12 +
13 +test_expect_success 'ls-files in empty repository' '
14 + git ls-files >actual &&
15 + test_cmp empty actual
16 +'
17 +
18 +test_expect_success 'ls-files with nonexistent path' '
19 + git ls-files doesnotexist >actual &&
20 + test_cmp empty actual
21 +'
22 +
23 +test_expect_success 'ls-files with nonsense option' '
24 + test_expect_code 129 git ls-files --nonsense 2>actual &&
25 + grep "[Uu]sage: git ls-files" actual
26 +'
27 +
28 +test_expect_success 'ls-files -h in corrupt repository' '
29 + mkdir broken &&
30 + (
31 + cd broken &&
32 + git init &&
33 + >.git/index &&
34 + test_expect_code 129 git ls-files -h >usage 2>&1
35 + ) &&
36 + grep "[Uu]sage: git ls-files " broken/usage
37 +'
38 +
39 +test_done