Skip to content

Commit 7e9c769

Browse files
committed
Combine "slashes" scripts and make it a fixture
Keeping the changes to make_traverse_dotdot_slashes.sh, this folds the make_traverse_dotgit_slsahes.sh logic into it, extracting the twice-used parts (which are most of the script) into a function that both call. Other changes: - No longer use command-line arguments. There are two repositories that are currently useful to make in this way, and this calls the function for each of them. - Change the style to mostly match that of other fixture scripts, including decreasing the indent from 4 to 2 and using the function keyword when defining functions. - Shorten variable names in cases where doing so is unambiguous (but not otherwise). - Eliminate the emit_payload function, since the new make_repo function now receives the content on standard input, which can be provided by whatever means is convenient (the current calls use a here string for the one-line file and a heredoc otherwise).
1 parent fe8c2c9 commit 7e9c769

File tree

3 files changed

+35
-62
lines changed

3 files changed

+35
-62
lines changed

gix-worktree/tests/fixtures/make_traverse_dotdot_slashes.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

gix-worktree/tests/fixtures/make_traverse_dotgit_slashes.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
# Makes a repo carrying a literally named file, which may even contain "/".
5+
# File content is from stdin. Arguments are repo name, file name, and file mode.
6+
function make_repo() (
7+
local repo="$1" file="$2" mode="$3"
8+
local blob_hash_escaped tree_hash commit_hash branch
9+
10+
git init -- "$repo"
11+
cd -- "$repo" # Temporary, as the function body is a ( ) subshell.
12+
13+
blob_hash_escaped="$(git hash-object -w --stdin | sed 's/../\\x&/g')"
14+
15+
tree_hash="$(
16+
printf "%s %s\\0$blob_hash_escaped" "$mode" "$file" |
17+
git hash-object -t tree -w --stdin --literally
18+
)"
19+
20+
commit_hash="$(git commit-tree -m 'Initial commit' "$tree_hash")"
21+
22+
branch="$(git symbolic-ref --short HEAD)"
23+
git branch -f -- "$branch" "$commit_hash"
24+
test -z "${DEBUG_FIXTURE-}" || git show # TODO: How should verbosity be controlled?
25+
)
26+
27+
make_repo traverse_dotdot_slashes ../outside 100644 \
28+
<<<'A file outside the working tree, somehow.'
29+
30+
# TODO: Should the payload be simplified to a single side effect for tests to check?
31+
make_repo traverse_dotgit_slashes .git/hooks/pre-commit 100755 <<'EOF'
32+
#!/bin/sh
33+
printf 'Vulnerable!\n'
34+
date >vulnerable
35+
EOF

0 commit comments

Comments
 (0)