3 test_description
='git bugreport'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # Headers "[System Info]" will be followed by a non-empty line if we put some
9 # information there; we can make sure all our headers were followed by some
10 # information to check if the command was successful.
11 HEADER_PATTERN
="^\[.*\]$"
13 check_all_headers_populated
() {
16 if test "$(grep "$HEADER_PATTERN" "$line")"
20 if test -z "$nextline"; then
27 test_expect_success
'creates a report with content in the right places' '
28 test_when_finished rm git-bugreport-check-headers.txt &&
29 git bugreport -s check-headers &&
30 check_all_headers_populated <git-bugreport-check-headers.txt
33 test_expect_success
'dies if file with same name as report already exists' '
34 test_when_finished rm git-bugreport-duplicate.txt &&
35 >>git-bugreport-duplicate.txt &&
36 test_must_fail git bugreport --suffix duplicate
39 test_expect_success
'--output-directory puts the report in the provided dir' '
40 test_when_finished rm -fr foo/ &&
41 git bugreport -o foo/ &&
42 test_path_is_file foo/git-bugreport-*
45 test_expect_success
'incorrect arguments abort with usage' '
46 test_must_fail git bugreport --false 2>output &&
47 test_i18ngrep usage output &&
48 test_path_is_missing git-bugreport-*
51 test_expect_success
'runs outside of a git dir' '
52 test_when_finished rm non-repo/git-bugreport-* &&
56 test_expect_success
'can create leading directories outside of a git dir' '
57 test_when_finished rm -fr foo/bar/baz &&
58 nongit git bugreport -o foo/bar/baz
61 test_expect_success
'indicates populated hooks' '
62 test_when_finished rm git-bugreport-hooks.txt &&
64 test_hook applypatch-msg <<-\EOF &&
67 test_hook unknown-hook <<-\EOF &&
70 git bugreport -s hooks &&
72 sort >expect <<-\EOF &&
77 sed -ne "/^\[Enabled Hooks\]$/,/^$/p" <git-bugreport-hooks.txt >actual &&
78 test_cmp expect actual
81 test_expect_success UNZIP
'--diagnose creates diagnostics zip archive' '
82 test_when_finished rm -rf report &&
84 git bugreport --diagnose -o report -s test >out &&
86 zip_path=report/git-diagnostics-test.zip &&
87 grep "Available space" out &&
88 test_path_is_file "$zip_path" &&
90 # Check zipped archive content
91 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
92 test_file_not_empty out &&
94 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
95 grep ".git/objects" out &&
97 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
98 grep "^Total: [0-9][0-9]*" out &&
100 # Should not include .git directory contents by default
101 ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/"
104 test_expect_success UNZIP
'--diagnose=stats excludes .git dir contents' '
105 test_when_finished rm -rf report &&
107 git bugreport --diagnose=stats -o report -s test >out &&
109 # Includes pack quantity/size info
110 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
111 grep ".git/objects" out &&
113 # Does not include .git directory contents
114 ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/"
117 test_expect_success UNZIP
'--diagnose=all includes .git dir contents' '
118 test_when_finished rm -rf report &&
120 git bugreport --diagnose=all -o report -s test >out &&
122 # Includes .git directory contents
123 "$GIT_UNZIP" -l "$zip_path" | grep ".git/" &&
125 "$GIT_UNZIP" -p "$zip_path" .git/HEAD >out &&
126 test_file_not_empty out