Skip to content

Commit 4c684ca

Browse files
committed
Start on demo script making repo with ../… filename
The repo this script makes contains a filename with a slash character in it that, if not rejected, will create a file above the working tree. This is a modification of make_traverse_dotgit_slashes.sh. Both require some further revision, and since most of their content is duplicated, it may be worthwhile to combine them to avoid that.
1 parent 6846c90 commit 4c684ca

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
readonly filename='../outside'
5+
readonly filemode=100644
6+
7+
emit_payload() {
8+
printf 'A file outside the working tree, somehow.\n'
9+
}
10+
11+
repo="$1"
12+
git init -- "$repo"
13+
cd -- "$repo"
14+
15+
blob_hash="$(emit_payload | git hash-object -w --stdin)"
16+
printf '%s' "$blob_hash" | xxd -r -p >blob-hash-bytes
17+
18+
tree_hash="$(
19+
printf '%s %s\0' "$filemode" "$filename" |
20+
cat - blob-hash-bytes |
21+
git hash-object -t tree -w --stdin --literally
22+
)"
23+
24+
rm blob-hash-bytes
25+
26+
commit_hash="$(git commit-tree -m 'Initial commit' "$tree_hash")"
27+
branch="$(git symbolic-ref --short HEAD)"
28+
git branch -f -- "$branch" "$commit_hash"
29+
git show

0 commit comments

Comments
 (0)