Junio C Hamano | c32056e | 2010-01-30 16:04:25 -0800 | [diff] [blame] | 1 | : included from t2016 and others |
| 2 | |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 3 | . ./test-lib.sh |
| 4 | |
Nguyễn Thái Ngọc Duy | 4df3ec6 | 2019-04-25 16:45:55 +0700 | [diff] [blame] | 5 | # set_state <path> <worktree-content> <index-content> |
| 6 | # |
| 7 | # Prepare the content for path in worktree and the index as specified. |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 8 | set_state () { |
| 9 | echo "$3" > "$1" && |
| 10 | git add "$1" && |
| 11 | echo "$2" > "$1" |
| 12 | } |
| 13 | |
Nguyễn Thái Ngọc Duy | 4df3ec6 | 2019-04-25 16:45:55 +0700 | [diff] [blame] | 14 | # save_state <path> |
| 15 | # |
| 16 | # Save index/worktree content of <path> in the files _worktree_<path> |
| 17 | # and _index_<path> |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 18 | save_state () { |
| 19 | noslash="$(echo "$1" | tr / _)" && |
| 20 | cat "$1" > _worktree_"$noslash" && |
| 21 | git show :"$1" > _index_"$noslash" |
| 22 | } |
| 23 | |
Nguyễn Thái Ngọc Duy | 4df3ec6 | 2019-04-25 16:45:55 +0700 | [diff] [blame] | 24 | # set_and_save_state <path> <worktree-content> <index-content> |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 25 | set_and_save_state () { |
| 26 | set_state "$@" && |
| 27 | save_state "$1" |
| 28 | } |
| 29 | |
Nguyễn Thái Ngọc Duy | 4df3ec6 | 2019-04-25 16:45:55 +0700 | [diff] [blame] | 30 | # verify_state <path> <expected-worktree-content> <expected-index-content> |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 31 | verify_state () { |
Ævar Arnfjörð Bjarmason | 62f3a45 | 2023-02-06 23:44:29 +0100 | [diff] [blame] | 32 | echo "$2" >expect && |
| 33 | test_cmp expect "$1" && |
| 34 | |
| 35 | echo "$3" >expect && |
| 36 | git show :"$1" >actual && |
| 37 | test_cmp expect actual |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Nguyễn Thái Ngọc Duy | 4df3ec6 | 2019-04-25 16:45:55 +0700 | [diff] [blame] | 40 | # verify_saved_state <path> |
| 41 | # |
| 42 | # Call verify_state with expected contents from the last save_state |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 43 | verify_saved_state () { |
| 44 | noslash="$(echo "$1" | tr / _)" && |
| 45 | verify_state "$1" "$(cat _worktree_"$noslash")" "$(cat _index_"$noslash")" |
| 46 | } |
| 47 | |
| 48 | save_head () { |
| 49 | git rev-parse HEAD > _head |
| 50 | } |
| 51 | |
| 52 | verify_saved_head () { |
Ævar Arnfjörð Bjarmason | 62f3a45 | 2023-02-06 23:44:29 +0100 | [diff] [blame] | 53 | git rev-parse HEAD >actual && |
| 54 | test_cmp _head actual |
Thomas Rast | b319ef7 | 2009-08-13 14:29:40 +0200 | [diff] [blame] | 55 | } |