Skip to content

Commit b319ef7

Browse files
trastgitster
authored andcommitted
Add a small patch-mode testing library
The tests for {reset,commit,stash} -p will frequently have to set both worktree and index states to known values, and verify that the outcome (again both worktree and index) are what was expected. Add a small helper library that lets us do these tasks more easily. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f0bef6 commit b319ef7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

t/lib-patch-mode.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
. ./test-lib.sh
2+
3+
set_state () {
4+
echo "$3" > "$1" &&
5+
git add "$1" &&
6+
echo "$2" > "$1"
7+
}
8+
9+
save_state () {
10+
noslash="$(echo "$1" | tr / _)" &&
11+
cat "$1" > _worktree_"$noslash" &&
12+
git show :"$1" > _index_"$noslash"
13+
}
14+
15+
set_and_save_state () {
16+
set_state "$@" &&
17+
save_state "$1"
18+
}
19+
20+
verify_state () {
21+
test "$(cat "$1")" = "$2" &&
22+
test "$(git show :"$1")" = "$3"
23+
}
24+
25+
verify_saved_state () {
26+
noslash="$(echo "$1" | tr / _)" &&
27+
verify_state "$1" "$(cat _worktree_"$noslash")" "$(cat _index_"$noslash")"
28+
}
29+
30+
save_head () {
31+
git rev-parse HEAD > _head
32+
}
33+
34+
verify_saved_head () {
35+
test "$(cat _head)" = "$(git rev-parse HEAD)"
36+
}

0 commit comments

Comments
 (0)