]>
Commit | Line | Data |
---|---|---|
d1cc130a SG |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Steven Grimm | |
4 | # | |
5 | ||
6 | test_description='git-commit | |
7 | ||
8 | Tests for selected commit options.' | |
9 | ||
10 | . ./test-lib.sh | |
11 | ||
12 | commit_msg_is () { | |
13 | test "`git log --pretty=format:%s%b -1`" = "$1" | |
14 | } | |
15 | ||
16 | # A sanity check to see if commit is working at all. | |
17 | test_expect_success 'a basic commit in an empty tree should succeed' ' | |
18 | echo content > foo && | |
19 | git add foo && | |
20 | git commit -m "initial commit" | |
21 | ' | |
22 | ||
23 | test_expect_success 'nonexistent template file should return error' ' | |
24 | echo changes >> foo && | |
25 | git add foo && | |
d492b31c | 26 | test_must_fail git commit --template "$PWD"/notexist |
d1cc130a SG |
27 | ' |
28 | ||
29 | test_expect_success 'nonexistent template file in config should return error' ' | |
30 | git config commit.template "$PWD"/notexist && | |
d492b31c | 31 | test_must_fail git commit && |
d1cc130a SG |
32 | git config --unset commit.template |
33 | ' | |
34 | ||
35 | # From now on we'll use a template file that exists. | |
36 | TEMPLATE="$PWD"/template | |
37 | ||
38 | test_expect_success 'unedited template should not commit' ' | |
39 | echo "template line" > "$TEMPLATE" && | |
d492b31c | 40 | test_must_fail git commit --template "$TEMPLATE" |
d1cc130a SG |
41 | ' |
42 | ||
43 | test_expect_success 'unedited template with comments should not commit' ' | |
44 | echo "# comment in template" >> "$TEMPLATE" && | |
d492b31c | 45 | test_must_fail git commit --template "$TEMPLATE" |
d1cc130a SG |
46 | ' |
47 | ||
48 | test_expect_success 'a Signed-off-by line by itself should not commit' ' | |
49 | ! GIT_EDITOR=../t7500/add-signed-off git commit --template "$TEMPLATE" | |
50 | ' | |
51 | ||
52 | test_expect_success 'adding comments to a template should not commit' ' | |
53 | ! GIT_EDITOR=../t7500/add-comments git commit --template "$TEMPLATE" | |
54 | ' | |
55 | ||
56 | test_expect_success 'adding real content to a template should commit' ' | |
57 | GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" && | |
58 | commit_msg_is "template linecommit message" | |
59 | ' | |
60 | ||
61 | test_expect_success '-t option should be short for --template' ' | |
62 | echo "short template" > "$TEMPLATE" && | |
63 | echo "new content" >> foo && | |
64 | git add foo && | |
65 | GIT_EDITOR=../t7500/add-content git commit -t "$TEMPLATE" && | |
66 | commit_msg_is "short templatecommit message" | |
67 | ' | |
68 | ||
69 | test_expect_success 'config-specified template should commit' ' | |
70 | echo "new template" > "$TEMPLATE" && | |
71 | git config commit.template "$TEMPLATE" && | |
72 | echo "more content" >> foo && | |
73 | git add foo && | |
74 | GIT_EDITOR=../t7500/add-content git commit && | |
75 | git config --unset commit.template && | |
76 | commit_msg_is "new templatecommit message" | |
77 | ' | |
78 | ||
79 | test_expect_success 'explicit commit message should override template' ' | |
80 | echo "still more content" >> foo && | |
81 | git add foo && | |
82 | GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \ | |
83 | -m "command line msg" && | |
55246aac | 84 | commit_msg_is "command line msg" |
d1cc130a SG |
85 | ' |
86 | ||
87 | test_expect_success 'commit message from file should override template' ' | |
88 | echo "content galore" >> foo && | |
89 | git add foo && | |
90 | echo "standard input msg" | | |
91 | GIT_EDITOR=../t7500/add-content git commit \ | |
92 | --template "$TEMPLATE" --file - && | |
55246aac | 93 | commit_msg_is "standard input msg" |
d1cc130a SG |
94 | ' |
95 | ||
859a4dbc RV |
96 | test_expect_success 'using alternate GIT_INDEX_FILE (1)' ' |
97 | ||
98 | cp .git/index saved-index && | |
99 | ( | |
100 | echo some new content >file && | |
101 | GIT_INDEX_FILE=.git/another_index && | |
102 | export GIT_INDEX_FILE && | |
103 | git add file && | |
104 | git commit -m "commit using another index" && | |
105 | git diff-index --exit-code HEAD && | |
106 | git diff-files --exit-code | |
107 | ) && | |
108 | cmp .git/index saved-index >/dev/null | |
109 | ||
110 | ' | |
111 | ||
112 | test_expect_success 'using alternate GIT_INDEX_FILE (2)' ' | |
113 | ||
114 | cp .git/index saved-index && | |
115 | ( | |
116 | rm -f .git/no-such-index && | |
117 | GIT_INDEX_FILE=.git/no-such-index && | |
118 | export GIT_INDEX_FILE && | |
119 | git commit -m "commit using nonexistent index" && | |
120 | test -z "$(git ls-files)" && | |
121 | test -z "$(git ls-tree HEAD)" | |
122 | ||
123 | ) && | |
124 | cmp .git/index saved-index >/dev/null | |
13208572 | 125 | ' |
859a4dbc | 126 | |
13208572 JS |
127 | cat > expect << EOF |
128 | zort | |
2150554b | 129 | |
13208572 JS |
130 | Signed-off-by: C O Mitter <committer@example.com> |
131 | EOF | |
132 | ||
133 | test_expect_success '--signoff' ' | |
134 | echo "yet another content *narf*" >> foo && | |
135 | echo "zort" | | |
136 | GIT_EDITOR=../t7500/add-content git commit -s -F - foo && | |
137 | git cat-file commit HEAD | sed "1,/^$/d" > output && | |
138 | diff expect output | |
859a4dbc RV |
139 | ' |
140 | ||
d1cc130a | 141 | test_done |