]>
Commit | Line | Data |
---|---|---|
238b439d ES |
1 | #!/bin/sh |
2 | ||
3 | test_description='git bugreport' | |
4 | ||
956d2e46 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
238b439d ES |
6 | . ./test-lib.sh |
7 | ||
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="^\[.*\]$" | |
12 | ||
13 | check_all_headers_populated () { | |
14 | while read -r line | |
15 | do | |
16 | if test "$(grep "$HEADER_PATTERN" "$line")" | |
17 | then | |
18 | echo "$line" | |
19 | read -r nextline | |
20 | if test -z "$nextline"; then | |
21 | return 1; | |
22 | fi | |
23 | fi | |
24 | done | |
25 | } | |
26 | ||
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 | |
31 | ' | |
32 | ||
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 | |
37 | ' | |
38 | ||
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-* | |
43 | ' | |
44 | ||
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-* | |
49 | ' | |
50 | ||
51 | test_expect_success 'runs outside of a git dir' ' | |
52 | test_when_finished rm non-repo/git-bugreport-* && | |
53 | nongit git bugreport | |
54 | ' | |
55 | ||
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 | |
59 | ' | |
60 | ||
788a7760 ES |
61 | test_expect_success 'indicates populated hooks' ' |
62 | test_when_finished rm git-bugreport-hooks.txt && | |
003cdf88 ÆAB |
63 | |
64 | test_hook applypatch-msg <<-\EOF && | |
65 | true | |
66 | EOF | |
67 | test_hook unknown-hook <<-\EOF && | |
68 | true | |
69 | EOF | |
788a7760 | 70 | git bugreport -s hooks && |
003cdf88 ÆAB |
71 | |
72 | sort >expect <<-\EOF && | |
73 | [Enabled Hooks] | |
74 | applypatch-msg | |
75 | EOF | |
76 | ||
77 | sed -ne "/^\[Enabled Hooks\]$/,/^$/p" <git-bugreport-hooks.txt >actual && | |
78 | test_cmp expect actual | |
788a7760 | 79 | ' |
238b439d | 80 | |
aac0e8ff VD |
81 | test_expect_success UNZIP '--diagnose creates diagnostics zip archive' ' |
82 | test_when_finished rm -rf report && | |
83 | ||
84 | git bugreport --diagnose -o report -s test >out && | |
85 | ||
86 | zip_path=report/git-diagnostics-test.zip && | |
87 | grep "Available space" out && | |
88 | test_path_is_file "$zip_path" && | |
89 | ||
90 | # Check zipped archive content | |
91 | "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out && | |
92 | test_file_not_empty out && | |
93 | ||
94 | "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && | |
95 | grep ".git/objects" out && | |
96 | ||
97 | "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out && | |
98 | grep "^Total: [0-9][0-9]*" out && | |
99 | ||
100 | # Should not include .git directory contents by default | |
101 | ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/" | |
102 | ' | |
103 | ||
104 | test_expect_success UNZIP '--diagnose=stats excludes .git dir contents' ' | |
105 | test_when_finished rm -rf report && | |
106 | ||
107 | git bugreport --diagnose=stats -o report -s test >out && | |
108 | ||
109 | # Includes pack quantity/size info | |
110 | "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && | |
111 | grep ".git/objects" out && | |
112 | ||
113 | # Does not include .git directory contents | |
114 | ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/" | |
115 | ' | |
116 | ||
117 | test_expect_success UNZIP '--diagnose=all includes .git dir contents' ' | |
118 | test_when_finished rm -rf report && | |
119 | ||
120 | git bugreport --diagnose=all -o report -s test >out && | |
121 | ||
122 | # Includes .git directory contents | |
123 | "$GIT_UNZIP" -l "$zip_path" | grep ".git/" && | |
124 | ||
125 | "$GIT_UNZIP" -p "$zip_path" .git/HEAD >out && | |
126 | test_file_not_empty out | |
127 | ' | |
128 | ||
238b439d | 129 | test_done |