3 test_description
='check git test library utility functions
5 Although the focus of this test suite as a whole is testing TopGit,
6 several of the utility functions are convenient front-ends for Git
9 Those are not tested by the testlib-basic tests so test the Git
19 # This isn't really necessary, but this is the "Git" test...
20 case "$(git version)" in
21 [Gg
][Ii
][Tt
]" "[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]" "[1-9]*)
24 error
"'git' seems to be missing"\
!
28 GAI
="$(git var GIT_AUTHOR_IDENT | sed 's/>.*/>/')" && [ -n "$GAI" ] &&
29 GCI
="$(git var GIT_COMMITTER_IDENT | sed 's/>.*/>/')" && [ -n "$GAI" ] ||
30 error
"failed to get GIT_AUTHOR_IDENT and/or GIT_COMMITTER_IDENT"\
!
33 git pack-refs
--all &&
34 rm -f .git
/packed-refs
&&
35 ! test -e .git
/packed-refs
&&
36 git read-tree
--empty &&
37 git symbolic-ref HEAD refs
/heads
/master
&&
38 ! git rev-parse
--verify --quiet refs
/heads
/master
--
42 cat .git
/config.bak
> .git
/config
45 test_expect_success
'no initial tick' '
46 test z"${test_tick:-none}" = z"none"
49 test_expect_success
'tick once' '
51 test z"$test_tick" = z"1112911993"
54 test_expect_success
'tick twice' '
57 test $test_tick -eq $((1112911993 + 60))
60 test_expect_success
'test_create_repo' '
61 test_create_repo repo &&
63 frd="$(cd repo && pwd -P)" &&
64 gtl="$(git -C repo rev-parse --show-toplevel)" &&
66 gtl="$(cd "$gtl" && pwd -P)" && test -n "$gtl" &&
67 test "$frd" = "$gtl" &&
71 test_expect_success
'commands fail with no repo' '
72 ! test_config foo.bar tar &&
73 ! test_unconfig foo.bar &&
76 ! test_cmp_rev HEAD HEAD &&
77 test_clear_when_finished
80 test_expect_success
'set global config without repo' '
81 git config --global yesuch.config global &&
82 test z"global" = z"$(git config yesuch.config)"
85 test_expect_success
'test_unconfig --global unset without repo' '
86 test_unconfig --global yesuch.config &&
87 test z = z"$(git config yesuch.global || :)"
90 test_expect_success
'test_unconfig --global already unset without repo' '
91 test_unconfig --global yesuch.config &&
92 test z = z"$(git config yesuch.global || :)"
95 git init
--quiet --template="$EMPTY_DIRECTORY" &&
96 cp .git
/config .git
/config.bak ||
97 error
"failed to initialize top repo"
99 test_expect_success
'test_unconfig already unset' '
100 test_unconfig nosuch.config &&
101 test z = z"$(git config nosuch.config || :)"
104 test_expect_success
'set local repo config' '
105 git config nosuch.config not &&
106 test z"not" = z"$(git config nosuch.config)"
109 test_expect_success
'test_unconfig' '
110 test_unconfig nosuch.config &&
111 test z = z"$(git config nosuch.config || :)"
114 test_expect_success
'nosuch.config exists not' '
116 test_must_fail git config nosuch.config
119 test_expect_success
'test_config sets config' '
121 test_config nosuch.config not &&
122 cfg="$(git config nosuch.config)" &&
123 test z"not" = z"$cfg"
126 test_expect_success LASTOK
'test_config auto unsets config' '
127 test_must_fail git config nosuch.config
130 test_expect_success
'set multivalued config' '
132 test_config nosuch.config not1 &&
133 git config --add nosuch.config not2 &&
134 test 2 -eq $(git config --get-all nosuch.config | wc -l)
137 test_expect_success LASTOK
'test_config auto unsets all config' '
138 test_must_fail git config nosuch.config
141 test_expect_success
'test_config_global sets config' '
143 test_config_global nosuch.config not &&
144 cfg="$(git config --global nosuch.config)" &&
145 test z"not" = z"$cfg"
148 test_expect_success LASTOK
'test_config_global auto unsets config' '
149 test_must_fail git config nosuch.config
152 test_expect_success
'set multivalued global config' '
154 test_config_global nosuch.config not1 &&
155 git config --global --add nosuch.config not2 &&
156 test 2 -eq $(git config --global --get-all nosuch.config | wc -l)
159 test_expect_success LASTOK
'test_config_global auto unsets all config' '
160 test_must_fail git config nosuch.config
163 test_expect_success
'test_commit --notick' '
165 test_commit --notick notick &&
166 git rev-parse --verify master -- &&
167 git rev-parse --verify notick -- &&
169 test z"notick" = z"$(cat notick.t)" &&
170 test z"notick" = z"$(git log --format="format:%B" -n 1)" &&
171 test z"1112911993" != z"$(git log --format="format:%ct" -n 1)"
174 test_expect_success
'test_commit (with tick)' '
176 test_commit withtick &&
177 git rev-parse --verify master -- &&
178 git rev-parse --verify withtick -- &&
179 test -e withtick.t &&
180 test z"withtick" = z"$(cat withtick.t)" &&
181 test z"withtick" = z"$(git log --format="format:%B" -n 1)" &&
182 test z"1112911993" = z"$(git log --format="format:%ct" -n 1)"
185 test_expect_success
'test_commit no defaults' '
187 test_commit nodefs no_defs.t no_defs_contents no_defs_tag &&
188 git rev-parse --verify master -- &&
189 git rev-parse --verify no_defs_tag -- &&
191 test z"no_defs_contents" = z"$(cat no_defs.t)" &&
192 test z"nodefs" = z"$(git log --format="format:%B" -n 1)"
195 test_expect_success
'test_commit --signoff' '
197 test_commit --signoff signoff &&
198 git rev-parse --verify master -- &&
199 git rev-parse --verify signoff -- &&
201 test z"signoff" = z"$(cat signoff.t)" &&
202 test z"signoff" = z"$(git log --format="format:%B" -n 1 | sed -n 1p)" &&
204 z"$(git log --format="format:%B" -n 1 | sed -n "/^Signed-off-by:/s/^.*: *//p")"
207 test_expect_success
'test_commit no tag' '
209 test_commit notag no_tag.t no_tag_contents "" &&
210 git rev-parse --verify master -- &&
211 test_must_fail git rev-parse --verify --quiet notag -- &&
213 test z"no_tag_contents" = z"$(cat no_tag.t)" &&
214 test z"notag" = z"$(git log --format="format:%B" -n 1)"
217 test_expect_success
'test_commit skip ~ tag' '
219 test_commit skip~tag &&
220 git rev-parse --verify master -- &&
221 test_must_fail git rev-parse --verify --quiet skip~tag -- &&
222 test -e skip~tag.t &&
223 test z"skip~tag" = z"$(cat skip~tag.t)" &&
224 test z"skip~tag" = z"$(git log --format="format:%B" -n 1)"
227 test_expect_success
'test_commit skip " " tag' '
229 test_commit "skip tag" &&
230 git rev-parse --verify master -- &&
231 test_must_fail git rev-parse --verify --quiet "skip tag" -- &&
232 test -e "skip tag.t" &&
233 test z"skip tag" = z"$(cat "skip tag.t")" &&
234 test z"skip tag" = z"$(git log --format="format:%B" -n 1)"
237 test_expect_success
'test_merge' '
239 test_commit one^file &&
240 git checkout -b topic base &&
241 test_commit merge^me &&
242 git checkout master &&
243 test_merge merged topic &&
244 test_debug git show-ref &&
245 test_debug git log $color --oneline --graph --decorate --date-order --branches --tags &&
246 test 2 -eq $(git log --format="format:%p" -n 1 | wc -w) &&
247 test_cmp_rev HEAD master &&
248 test_cmp_rev master merged