2010-01-31 01:04:25 +01:00
|
|
|
: included from t2016 and others
|
|
|
|
|
2009-08-13 14:29:40 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2019-04-25 11:45:55 +02:00
|
|
|
# set_state <path> <worktree-content> <index-content>
|
|
|
|
#
|
|
|
|
# Prepare the content for path in worktree and the index as specified.
|
2009-08-13 14:29:40 +02:00
|
|
|
set_state () {
|
|
|
|
echo "$3" > "$1" &&
|
|
|
|
git add "$1" &&
|
|
|
|
echo "$2" > "$1"
|
|
|
|
}
|
|
|
|
|
2019-04-25 11:45:55 +02:00
|
|
|
# save_state <path>
|
|
|
|
#
|
|
|
|
# Save index/worktree content of <path> in the files _worktree_<path>
|
|
|
|
# and _index_<path>
|
2009-08-13 14:29:40 +02:00
|
|
|
save_state () {
|
|
|
|
noslash="$(echo "$1" | tr / _)" &&
|
|
|
|
cat "$1" > _worktree_"$noslash" &&
|
|
|
|
git show :"$1" > _index_"$noslash"
|
|
|
|
}
|
|
|
|
|
2019-04-25 11:45:55 +02:00
|
|
|
# set_and_save_state <path> <worktree-content> <index-content>
|
2009-08-13 14:29:40 +02:00
|
|
|
set_and_save_state () {
|
|
|
|
set_state "$@" &&
|
|
|
|
save_state "$1"
|
|
|
|
}
|
|
|
|
|
2019-04-25 11:45:55 +02:00
|
|
|
# verify_state <path> <expected-worktree-content> <expected-index-content>
|
2009-08-13 14:29:40 +02:00
|
|
|
verify_state () {
|
2023-02-06 23:44:29 +01:00
|
|
|
echo "$2" >expect &&
|
|
|
|
test_cmp expect "$1" &&
|
|
|
|
|
|
|
|
echo "$3" >expect &&
|
|
|
|
git show :"$1" >actual &&
|
|
|
|
test_cmp expect actual
|
2009-08-13 14:29:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 11:45:55 +02:00
|
|
|
# verify_saved_state <path>
|
|
|
|
#
|
|
|
|
# Call verify_state with expected contents from the last save_state
|
2009-08-13 14:29:40 +02:00
|
|
|
verify_saved_state () {
|
|
|
|
noslash="$(echo "$1" | tr / _)" &&
|
|
|
|
verify_state "$1" "$(cat _worktree_"$noslash")" "$(cat _index_"$noslash")"
|
|
|
|
}
|
|
|
|
|
|
|
|
save_head () {
|
|
|
|
git rev-parse HEAD > _head
|
|
|
|
}
|
|
|
|
|
|
|
|
verify_saved_head () {
|
2023-02-06 23:44:29 +01:00
|
|
|
git rev-parse HEAD >actual &&
|
|
|
|
test_cmp _head actual
|
2009-08-13 14:29:40 +02:00
|
|
|
}
|