Repository navigation
Expand file tree
/
Copy pathcommit.sh
More file actions
130 lines (130 loc) · 5.73 KB
/
Copy pathcommit.sh
File metadata and controls
130 lines (130 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -eu
git init --initial-branch=master repo
cd repo
case "$1" in
spaces|unicode-separators)
# Construct trees directly: Windows rejects trailing spaces in index paths.
paths=(name ' name' 'name ' ' name ' ' ')
if [ "$1" = unicode-separators ]; then
git config core.quotePath false
paths=($'before\302\205after.txt' $'before\342\200\250after.txt' $'before\342\200\251after.txt')
fi
for multiplier in 1 2; do
tree=$(
count=0
for path in "${paths[@]}"; do
if [ "$1" = spaces ]; then count=$((count + 1)); else count=1; fi
oid=$(for ((line=0; line<count*multiplier; line++)); do printf 'line\n'; done | git hash-object -w --stdin)
printf '100644 blob %s\t%s\0' "$oid" "$path"
done | git mktree -z
)
if [ "$multiplier" = 1 ]; then
commit=$(git commit-tree "$tree" -m 'Update files')
else
commit=$(git commit-tree "$tree" -p "$commit" -m 'Update files')
fi
git tag "update-$multiplier" "$commit"
done
commit=$(git commit-tree "$tree" -p "$commit" -m 'No changes')
git tag empty "$commit"
tree=$(git mktree </dev/null)
commit=$(git commit-tree "$tree" -p "$commit" -m 'Remove files')
git tag removed "$commit"
git update-ref refs/heads/master "$commit"
;;
ambiguous)
touch master
git add master
git commit -m 'initial commit'
;;
tree|latin1)
touch hello.txt
git add hello.txt
git write-tree > ../tree-id
if [ "$1" = latin1 ]; then git config i18n.commitencoding ISO-8859-1; fi
;;
raw)
git hash-object --literally -w -t commit "$2" > ../object-id
;;
trailing-date|zero-offset)
date='1112591163 +0200 1700000000 -0500'
if [ "$1" = zero-offset ]; then date='1112591163 -0000'; fi
tree=$(git mktree </dev/null)
{
printf 'tree %s\n' "$tree"
printf 'author A <a@example.com> %s\n' "$date"
printf 'committer C <c@example.com> %s\n' "$date"
printf '\nmessage\n'
} | git hash-object --literally -w -t commit --stdin > ../object-id
{
printf 'object %s\ntype commit\ntag v1\n' "$(cat ../object-id)"
printf 'tagger T <t@example.com> %s\n' "$date"
printf '\nmessage\n'
} | git hash-object --literally -w -t tag --stdin > ../tag-id
git update-ref refs/tags/v1 "$(cat ../tag-id)"
;;
whitespace-headers)
tree=$(git mktree </dev/null)
{
printf 'tree %s\n' "$tree"
printf 'author Andr\351 <andre@example.com> 1112591163 +0200\n'
printf 'committer Andr\351 <andre@example.com> 1112591163 +0200\n'
printf 'x-note a\n'
case "$2" in
cr) printf '\r\n' ;;
space) printf ' \n' ;;
tab) printf '\t\n' ;;
*) exit 1 ;;
esac
printf 'Co-authored-by: Mallory <mallory@example.com>\n'
printf 'encoding ISO-8859-1\n\nR\351sum\351\n'
} | git hash-object --literally -w -t commit --stdin > ../object-id
;;
encoding)
tree=$(git mktree </dev/null)
{
printf 'tree %s\n' "$tree"
if [ "$2" = utf8 ]; then
printf 'author Andr\303\251 <andre@example.com> 1112591163 +0200\n'
printf 'committer Andr\303\251 <andre@example.com> 1112591163 +0200\n'
elif [ "$2" = git-only-codec ]; then
printf 'author \033$)A\016VPND\017 <andre@example.com> 1112591163 +0200\n'
printf 'committer \033$)A\016VPND\017 <andre@example.com> 1112591163 +0200\n'
else
printf 'author Andr\351 <andre@example.com> 1112591163 +0200\n'
printf 'committer Andr\351 <andre@example.com> 1112591163 +0200\n'
fi
case "$2" in
utf8) printf 'encoding UTF-8\n' ;;
git-only-codec) printf 'encoding ISO-2022-CN\n' ;;
latin1|latin1-signature) printf 'encoding ISO-8859-1\n' ;;
utf16-signature) printf 'encoding utf-16-be\n' ;;
late-latin1) printf 'x-extra value\nencoding ISO-8859-1\n' ;;
unknown) printf 'encoding pony-speak\n' ;;
nontext) printf 'encoding base64_codec\n' ;;
nonascii) printf 'encoding utf-\3778\n' ;;
utf16-then-latin1) printf 'encoding utf-16-be\nencoding ISO-8859-1\n' ;;
utf16be-then-latin1) printf 'encoding UTF-16BE\nencoding ISO-8859-1\n' ;;
latin1-then-nonascii) printf 'encoding ISO-8859-1\nencoding utf-\3778\n' ;;
latin1-then-utf8) printf 'encoding ISO-8859-1\nencoding UTF-8\n' ;;
unknown-then-latin1) printf 'encoding pony-speak\nencoding ISO-8859-1\n' ;;
empty-then-latin1) printf 'encoding \nencoding ISO-8859-1\n' ;;
*) exit 1 ;;
esac
case "$2" in
*-signature) printf 'gpgsig sign\351\n continued\351\n' ;;
esac
if [ "$2" = utf8 ]; then
printf '\nR\303\251sum\303\251\n'
elif [ "$2" = git-only-codec ]; then
printf '\n\033$)A\016VPND\017\n'
elif [ "$2" = utf16-then-latin1 ]; then
# Odd-sized commits force UTF-16 conversion to fail.
printf '\nR\351sum\351!\n'
else
printf '\nR\351sum\351\n'
fi
} | git hash-object --literally -w -t commit --stdin > ../object-id
;;
esac