Skip to content

Commit fe8c2c9

Browse files
committed
Adjust make_traverse_dotdot_slashes.sh for environment
These are changes that do not significantly affect behavior but use the set of tools that should be availalble in testing environments, as well as refactorings that are useful to do not before really making this usable as a fixture. - Use bash shebang, enable pipefail. - Don't require xxd. - Don't create an extra temporary file. - Shorten, simplify, and clarify some logic.
1 parent ccbc119 commit fe8c2c9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

gix-worktree/tests/fixtures/make_traverse_dotdot_slashes.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
#!/bin/sh
2-
set -eu
1+
#!/bin/bash
2+
set -eu -o pipefail
33

44
readonly filename='../outside'
55
readonly filemode=100644
66

77
emit_payload() {
8-
printf 'A file outside the working tree, somehow.\n'
8+
echo 'A file outside the working tree, somehow.'
99
}
1010

1111
repo="$1"
1212
git init -- "$repo"
1313
cd -- "$repo"
1414

15-
blob_hash="$(emit_payload | git hash-object -w --stdin)"
16-
printf '%s' "$blob_hash" | xxd -r -p >blob-hash-bytes
15+
blob_hash_escaped="$(
16+
emit_payload |
17+
git hash-object -w --stdin |
18+
sed 's/../\\x&/g'
19+
)"
1720

1821
tree_hash="$(
19-
printf '%s %s\0' "$filemode" "$filename" |
20-
cat - blob-hash-bytes |
22+
printf "%s %s\\0$blob_hash_escaped" "$filemode" "$filename" |
2123
git hash-object -t tree -w --stdin --literally
2224
)"
2325

24-
rm blob-hash-bytes
25-
2626
commit_hash="$(git commit-tree -m 'Initial commit' "$tree_hash")"
2727
branch="$(git symbolic-ref --short HEAD)"
2828
git branch -f -- "$branch" "$commit_hash"

0 commit comments

Comments
 (0)