]>
Commit | Line | Data |
---|---|---|
6f6826c5 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Rewrite revision history | |
4 | # Copyright (c) Petr Baudis, 2006 | |
5 | # Minimal changes to "port" it to core-git (c) Johannes Schindelin, 2007 | |
6 | # | |
c401b33c JS |
7 | # Lets you rewrite the revision history of the current branch, creating |
8 | # a new branch. You can specify a number of filters to modify the commits, | |
9 | # files and trees. | |
6f6826c5 | 10 | |
16ed34ad JS |
11 | # The following functions will also be available in the commit filter: |
12 | ||
13 | functions=$(cat << \EOF | |
b5669a05 | 14 | warn () { |
285c6cbf | 15 | echo "$*" >&2 |
b5669a05 SP |
16 | } |
17 | ||
6f6826c5 JS |
18 | map() |
19 | { | |
3520e1e8 | 20 | # if it was not rewritten, take the original |
c57a3494 JS |
21 | if test -r "$workdir/../map/$1" |
22 | then | |
23 | cat "$workdir/../map/$1" | |
24 | else | |
25 | echo "$1" | |
26 | fi | |
6f6826c5 JS |
27 | } |
28 | ||
f95eef15 JS |
29 | # if you run 'skip_commit "$@"' in a commit filter, it will print |
30 | # the (mapped) parents, effectively skipping the commit. | |
31 | ||
32 | skip_commit() | |
33 | { | |
34 | shift; | |
35 | while [ -n "$1" ]; | |
36 | do | |
37 | shift; | |
38 | map "$1"; | |
39 | shift; | |
40 | done; | |
41 | } | |
42 | ||
d3240d93 PH |
43 | # if you run 'git_commit_non_empty_tree "$@"' in a commit filter, |
44 | # it will skip commits that leave the tree untouched, commit the other. | |
45 | git_commit_non_empty_tree() | |
46 | { | |
47 | if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then | |
48 | map "$3" | |
49 | else | |
50 | git commit-tree "$@" | |
51 | fi | |
52 | } | |
8c1ce0f4 JS |
53 | # override die(): this version puts in an extra line break, so that |
54 | # the progress is still visible | |
55 | ||
56 | die() | |
57 | { | |
58 | echo >&2 | |
59 | echo "$*" >&2 | |
60 | exit 1 | |
61 | } | |
16ed34ad JS |
62 | EOF |
63 | ) | |
64 | ||
65 | eval "$functions" | |
8c1ce0f4 | 66 | |
3c730fab JK |
67 | finish_ident() { |
68 | # Ensure non-empty id name. | |
69 | echo "case \"\$GIT_$1_NAME\" in \"\") GIT_$1_NAME=\"\${GIT_$1_EMAIL%%@*}\" && export GIT_$1_NAME;; esac" | |
70 | # And make sure everything is exported. | |
71 | echo "export GIT_$1_NAME" | |
72 | echo "export GIT_$1_EMAIL" | |
73 | echo "export GIT_$1_DATE" | |
74 | } | |
6f6826c5 JS |
75 | |
76 | set_ident () { | |
3c730fab JK |
77 | parse_ident_from_commit author AUTHOR committer COMMITTER |
78 | finish_ident AUTHOR | |
79 | finish_ident COMMITTER | |
6f6826c5 JS |
80 | } |
81 | ||
83e355a6 | 82 | USAGE="[--env-filter <command>] [--tree-filter <command>] |
9dcca58d JH |
83 | [--index-filter <command>] [--parent-filter <command>] |
84 | [--msg-filter <command>] [--commit-filter <command>] | |
85 | [--tag-name-filter <command>] [--subdirectory-filter <directory>] | |
86 | [--original <namespace>] [-d <directory>] [-f | --force] | |
87 | [<rev-list options>...]" | |
7e0f1704 | 88 | |
8f321a39 | 89 | OPTIONS_SPEC= |
7e0f1704 JS |
90 | . git-sh-setup |
91 | ||
a4661b01 | 92 | if [ "$(is_bare_repository)" = false ]; then |
5347a50f | 93 | require_clean_work_tree 'rewrite branches' |
a4661b01 | 94 | fi |
46eb449c | 95 | |
6f6826c5 | 96 | tempdir=.git-rewrite |
6f6826c5 JS |
97 | filter_env= |
98 | filter_tree= | |
99 | filter_index= | |
100 | filter_parent= | |
101 | filter_msg=cat | |
d3240d93 | 102 | filter_commit= |
6f6826c5 | 103 | filter_tag_name= |
685ef546 | 104 | filter_subdir= |
dfd05e38 JS |
105 | orig_namespace=refs/original/ |
106 | force= | |
d3240d93 | 107 | prune_empty= |
f2f3a6b8 | 108 | remap_to_ancestor= |
822f7c73 | 109 | while : |
6f6826c5 JS |
110 | do |
111 | case "$1" in | |
112 | --) | |
113 | shift | |
114 | break | |
115 | ;; | |
dfd05e38 JS |
116 | --force|-f) |
117 | shift | |
118 | force=t | |
119 | continue | |
120 | ;; | |
f2f3a6b8 | 121 | --remap-to-ancestor) |
7ec344d8 | 122 | # deprecated ($remap_to_ancestor is set now automatically) |
f2f3a6b8 TR |
123 | shift |
124 | remap_to_ancestor=t | |
125 | continue | |
126 | ;; | |
d3240d93 PH |
127 | --prune-empty) |
128 | shift | |
129 | prune_empty=t | |
130 | continue | |
131 | ;; | |
6f6826c5 JS |
132 | -*) |
133 | ;; | |
134 | *) | |
135 | break; | |
136 | esac | |
137 | ||
138 | # all switches take one argument | |
139 | ARG="$1" | |
140 | case "$#" in 1) usage ;; esac | |
141 | shift | |
142 | OPTARG="$1" | |
143 | shift | |
144 | ||
145 | case "$ARG" in | |
146 | -d) | |
147 | tempdir="$OPTARG" | |
148 | ;; | |
6f6826c5 JS |
149 | --env-filter) |
150 | filter_env="$OPTARG" | |
151 | ;; | |
152 | --tree-filter) | |
153 | filter_tree="$OPTARG" | |
154 | ;; | |
155 | --index-filter) | |
156 | filter_index="$OPTARG" | |
157 | ;; | |
158 | --parent-filter) | |
159 | filter_parent="$OPTARG" | |
160 | ;; | |
161 | --msg-filter) | |
162 | filter_msg="$OPTARG" | |
163 | ;; | |
164 | --commit-filter) | |
16ed34ad | 165 | filter_commit="$functions; $OPTARG" |
6f6826c5 JS |
166 | ;; |
167 | --tag-name-filter) | |
168 | filter_tag_name="$OPTARG" | |
169 | ;; | |
685ef546 JS |
170 | --subdirectory-filter) |
171 | filter_subdir="$OPTARG" | |
f2f3a6b8 | 172 | remap_to_ancestor=t |
685ef546 | 173 | ;; |
dfd05e38 | 174 | --original) |
55ced83d | 175 | orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/ |
dfd05e38 | 176 | ;; |
6f6826c5 JS |
177 | *) |
178 | usage | |
179 | ;; | |
180 | esac | |
181 | done | |
182 | ||
d3240d93 PH |
183 | case "$prune_empty,$filter_commit" in |
184 | ,) | |
185 | filter_commit='git commit-tree "$@"';; | |
186 | t,) | |
187 | filter_commit="$functions;"' git_commit_non_empty_tree "$@"';; | |
188 | ,*) | |
189 | ;; | |
190 | *) | |
5da81713 | 191 | die "Cannot set --prune-empty and --commit-filter at the same time" |
d3240d93 PH |
192 | esac |
193 | ||
dfd05e38 JS |
194 | case "$force" in |
195 | t) | |
196 | rm -rf "$tempdir" | |
197 | ;; | |
198 | '') | |
199 | test -d "$tempdir" && | |
200 | die "$tempdir already exists, please remove it" | |
201 | esac | |
97276019 | 202 | orig_dir=$(pwd) |
af580e9c | 203 | mkdir -p "$tempdir/t" && |
dfd05e38 | 204 | tempdir="$(cd "$tempdir"; pwd)" && |
af580e9c JS |
205 | cd "$tempdir/t" && |
206 | workdir="$(pwd)" || | |
207 | die "" | |
6f6826c5 | 208 | |
def16e71 | 209 | # Remove tempdir on exit |
97276019 | 210 | trap 'cd "$orig_dir"; rm -rf "$tempdir"' 0 |
def16e71 | 211 | |
88e38808 LN |
212 | ORIG_GIT_DIR="$GIT_DIR" |
213 | ORIG_GIT_WORK_TREE="$GIT_WORK_TREE" | |
214 | ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE" | |
215 | GIT_WORK_TREE=. | |
216 | export GIT_DIR GIT_WORK_TREE | |
217 | ||
dfd05e38 | 218 | # Make sure refs/original is empty |
0ea29cce | 219 | git for-each-ref > "$tempdir"/backup-refs || exit |
dfd05e38 JS |
220 | while read sha1 type name |
221 | do | |
222 | case "$force,$name" in | |
223 | ,$orig_namespace*) | |
734cd572 JT |
224 | die "Cannot create a new backup. |
225 | A previous backup already exists in $orig_namespace | |
226 | Force overwriting the backup with -f" | |
dfd05e38 JS |
227 | ;; |
228 | t,$orig_namespace*) | |
229 | git update-ref -d "$name" $sha1 | |
230 | ;; | |
231 | esac | |
232 | done < "$tempdir"/backup-refs | |
233 | ||
418fa3a5 | 234 | # The refs should be updated if their heads were rewritten |
0ea29cce EK |
235 | git rev-parse --no-flags --revs-only --symbolic-full-name \ |
236 | --default HEAD "$@" > "$tempdir"/raw-heads || exit | |
237 | sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads | |
dfd05e38 JS |
238 | |
239 | test -s "$tempdir"/heads || | |
240 | die "Which ref do you want to rewrite?" | |
241 | ||
3addc94a JS |
242 | GIT_INDEX_FILE="$(pwd)/../index" |
243 | export GIT_INDEX_FILE | |
6f6826c5 | 244 | |
af580e9c JS |
245 | # map old->new commit ids for rewriting parents |
246 | mkdir ../map || die "Could not create map/ directory" | |
6f6826c5 | 247 | |
2c1d2d81 TR |
248 | # we need "--" only if there are no path arguments in $@ |
249 | nonrevs=$(git rev-parse --no-revs "$@") || exit | |
7ec344d8 CH |
250 | if test -z "$nonrevs" |
251 | then | |
252 | dashdash=-- | |
253 | else | |
254 | dashdash= | |
255 | remap_to_ancestor=t | |
256 | fi | |
257 | ||
3361a548 | 258 | git rev-parse --revs-only "$@" >../parse |
2c1d2d81 | 259 | |
685ef546 JS |
260 | case "$filter_subdir" in |
261 | "") | |
2c1d2d81 | 262 | eval set -- "$(git rev-parse --sq --no-revs "$@")" |
685ef546 JS |
263 | ;; |
264 | *) | |
2c1d2d81 TR |
265 | eval set -- "$(git rev-parse --sq --no-revs "$@" $dashdash \ |
266 | "$filter_subdir")" | |
267 | ;; | |
268 | esac | |
269 | ||
270 | git rev-list --reverse --topo-order --default HEAD \ | |
3361a548 | 271 | --parents --simplify-merges --stdin "$@" <../parse >../revs || |
2c1d2d81 | 272 | die "Could not get the commits" |
9d6f220c | 273 | commits=$(wc -l <../revs | tr -d " ") |
6f6826c5 JS |
274 | |
275 | test $commits -eq 0 && die "Found nothing to rewrite" | |
276 | ||
dfd05e38 | 277 | # Rewrite the commits |
6a9d16a0 GB |
278 | report_progress () |
279 | { | |
280 | if test -n "$progress" && | |
281 | test $git_filter_branch__commit_count -gt $next_sample_at | |
282 | then | |
71400d97 JH |
283 | count=$git_filter_branch__commit_count |
284 | ||
285 | now=$(date +%s) | |
286 | elapsed=$(($now - $start_timestamp)) | |
287 | remaining=$(( ($commits - $count) * $elapsed / $count )) | |
288 | if test $elapsed -gt 0 | |
6a9d16a0 | 289 | then |
71400d97 | 290 | next_sample_at=$(( ($elapsed + 1) * $count / $elapsed )) |
6a9d16a0 GB |
291 | else |
292 | next_sample_at=$(($next_sample_at + 1)) | |
293 | fi | |
71400d97 | 294 | progress=" ($elapsed seconds passed, remaining $remaining predicted)" |
6a9d16a0 | 295 | fi |
71400d97 | 296 | printf "\rRewrite $commit ($count/$commits)$progress " |
6a9d16a0 | 297 | } |
dfd05e38 | 298 | |
d5b0c97d | 299 | git_filter_branch__commit_count=0 |
6a9d16a0 GB |
300 | |
301 | progress= start_timestamp= | |
302 | if date '+%s' 2>/dev/null | grep -q '^[0-9][0-9]*$' | |
303 | then | |
304 | next_sample_at=0 | |
305 | progress="dummy to ensure this is not empty" | |
306 | start_timestamp=$(date '+%s') | |
307 | fi | |
308 | ||
348d4f2f JK |
309 | if test -n "$filter_index" || |
310 | test -n "$filter_tree" || | |
311 | test -n "$filter_subdir" | |
312 | then | |
313 | need_index=t | |
314 | else | |
315 | need_index= | |
316 | fi | |
317 | ||
813b4734 | 318 | while read commit parents; do |
d5b0c97d | 319 | git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1)) |
6a9d16a0 GB |
320 | |
321 | report_progress | |
6f6826c5 | 322 | |
685ef546 JS |
323 | case "$filter_subdir" in |
324 | "") | |
348d4f2f JK |
325 | if test -n "$need_index" |
326 | then | |
327 | GIT_ALLOW_NULL_SHA1=1 git read-tree -i -m $commit | |
328 | fi | |
685ef546 JS |
329 | ;; |
330 | *) | |
5b044ac3 | 331 | # The commit may not have the subdirectory at all |
83bd7437 JK |
332 | err=$(GIT_ALLOW_NULL_SHA1=1 \ |
333 | git read-tree -i -m $commit:"$filter_subdir" 2>&1) || { | |
d69da76d | 334 | if ! git rev-parse -q --verify $commit:"$filter_subdir" |
5b044ac3 JH |
335 | then |
336 | rm -f "$GIT_INDEX_FILE" | |
337 | else | |
338 | echo >&2 "$err" | |
339 | false | |
340 | fi | |
341 | } | |
af580e9c | 342 | esac || die "Could not initialize the index" |
6f6826c5 | 343 | |
3addc94a JS |
344 | GIT_COMMIT=$commit |
345 | export GIT_COMMIT | |
af580e9c JS |
346 | git cat-file commit "$commit" >../commit || |
347 | die "Cannot read commit $commit" | |
6f6826c5 | 348 | |
3c730fab JK |
349 | eval "$(set_ident <../commit)" || |
350 | die "setting author/committer failed for commit $commit" | |
8c1ce0f4 JS |
351 | eval "$filter_env" < /dev/null || |
352 | die "env filter failed: $filter_env" | |
6f6826c5 JS |
353 | |
354 | if [ "$filter_tree" ]; then | |
af580e9c JS |
355 | git checkout-index -f -u -a || |
356 | die "Could not checkout the index" | |
6f6826c5 JS |
357 | # files that $commit removed are now still in the working tree; |
358 | # remove them, else they would be added again | |
6a589fda | 359 | git clean -d -q -f -x |
8c1ce0f4 JS |
360 | eval "$filter_tree" < /dev/null || |
361 | die "tree filter failed: $filter_tree" | |
362 | ||
1fe32cb9 | 363 | ( |
4d2a3646 | 364 | git diff-index -r --name-only --ignore-submodules $commit -- && |
1fe32cb9 | 365 | git ls-files --others |
0ea29cce EK |
366 | ) > "$tempdir"/tree-state || exit |
367 | git update-index --add --replace --remove --stdin \ | |
368 | < "$tempdir"/tree-state || exit | |
6f6826c5 JS |
369 | fi |
370 | ||
8c1ce0f4 JS |
371 | eval "$filter_index" < /dev/null || |
372 | die "index filter failed: $filter_index" | |
6f6826c5 JS |
373 | |
374 | parentstr= | |
813b4734 | 375 | for parent in $parents; do |
3520e1e8 | 376 | for reparent in $(map "$parent"); do |
79bc4ef3 CB |
377 | case "$parentstr " in |
378 | *" -p $reparent "*) | |
379 | ;; | |
380 | *) | |
381 | parentstr="$parentstr -p $reparent" | |
382 | ;; | |
383 | esac | |
3520e1e8 | 384 | done |
6f6826c5 JS |
385 | done |
386 | if [ "$filter_parent" ]; then | |
8c1ce0f4 JS |
387 | parentstr="$(echo "$parentstr" | eval "$filter_parent")" || |
388 | die "parent filter failed: $filter_parent" | |
6f6826c5 JS |
389 | fi |
390 | ||
df062010 | 391 | { |
a5a4b3ff | 392 | while IFS='' read -r header_line && test -n "$header_line" |
df062010 JK |
393 | do |
394 | # skip header lines... | |
395 | :; | |
396 | done | |
397 | # and output the actual commit message | |
398 | cat | |
399 | } <../commit | | |
8c1ce0f4 JS |
400 | eval "$filter_msg" > ../message || |
401 | die "msg filter failed: $filter_msg" | |
348d4f2f JK |
402 | |
403 | if test -n "$need_index" | |
404 | then | |
405 | tree=$(git write-tree) | |
406 | else | |
1dc413eb | 407 | tree=$(git rev-parse "$commit^{tree}") |
348d4f2f | 408 | fi |
0906f6e1 | 409 | workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \ |
348d4f2f | 410 | "$tree" $parentstr < ../message > ../map/$commit || |
0ea29cce | 411 | die "could not write rewritten commit" |
6f6826c5 JS |
412 | done <../revs |
413 | ||
f2f3a6b8 TR |
414 | # If we are filtering for paths, as in the case of a subdirectory |
415 | # filter, it is possible that a specified head is not in the set of | |
416 | # rewritten commits, because it was pruned by the revision walker. | |
417 | # Ancestor remapping fixes this by mapping these heads to the unique | |
418 | # nearest ancestor that survived the pruning. | |
dfd05e38 | 419 | |
f2f3a6b8 | 420 | if test "$remap_to_ancestor" = t |
a0e46390 TR |
421 | then |
422 | while read ref | |
dfd05e38 | 423 | do |
a0e46390 TR |
424 | sha1=$(git rev-parse "$ref"^0) |
425 | test -f "$workdir"/../map/$sha1 && continue | |
2c1d2d81 | 426 | ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@") |
a0e46390 TR |
427 | test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1 |
428 | done < "$tempdir"/heads | |
429 | fi | |
dfd05e38 JS |
430 | |
431 | # Finally update the refs | |
432 | ||
433 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' | |
434 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" | |
dfd05e38 JS |
435 | echo |
436 | while read ref | |
437 | do | |
438 | # avoid rewriting a ref twice | |
439 | test -f "$orig_namespace$ref" && continue | |
440 | ||
441 | sha1=$(git rev-parse "$ref"^0) | |
442 | rewritten=$(map $sha1) | |
443 | ||
444 | test $sha1 = "$rewritten" && | |
445 | warn "WARNING: Ref '$ref' is unchanged" && | |
446 | continue | |
447 | ||
448 | case "$rewritten" in | |
449 | '') | |
450 | echo "Ref '$ref' was deleted" | |
451 | git update-ref -m "filter-branch: delete" -d "$ref" $sha1 || | |
452 | die "Could not delete $ref" | |
98409060 | 453 | ;; |
dfd05e38 JS |
454 | $_x40) |
455 | echo "Ref '$ref' was rewritten" | |
261044e8 TR |
456 | if ! git update-ref -m "filter-branch: rewrite" \ |
457 | "$ref" $rewritten $sha1 2>/dev/null; then | |
458 | if test $(git cat-file -t "$ref") = tag; then | |
459 | if test -z "$filter_tag_name"; then | |
460 | warn "WARNING: You said to rewrite tagged commits, but not the corresponding tag." | |
461 | warn "WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag." | |
462 | fi | |
463 | else | |
464 | die "Could not rewrite $ref" | |
465 | fi | |
466 | fi | |
98409060 | 467 | ;; |
dfd05e38 JS |
468 | *) |
469 | # NEEDSWORK: possibly add -Werror, making this an error | |
470 | warn "WARNING: '$ref' was rewritten into multiple commits:" | |
471 | warn "$rewritten" | |
472 | warn "WARNING: Ref '$ref' points to the first one now." | |
473 | rewritten=$(echo "$rewritten" | head -n 1) | |
474 | git update-ref -m "filter-branch: rewrite to first" \ | |
475 | "$ref" $rewritten $sha1 || | |
476 | die "Could not rewrite $ref" | |
477 | ;; | |
478 | esac | |
0ea29cce EK |
479 | git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 || |
480 | exit | |
dfd05e38 JS |
481 | done < "$tempdir"/heads |
482 | ||
483 | # TODO: This should possibly go, with the semantics that all positive given | |
484 | # refs are updated, and their original heads stored in refs/original/ | |
485 | # Filter tags | |
6f6826c5 JS |
486 | |
487 | if [ "$filter_tag_name" ]; then | |
5be60078 | 488 | git for-each-ref --format='%(objectname) %(objecttype) %(refname)' refs/tags | |
6f6826c5 JS |
489 | while read sha1 type ref; do |
490 | ref="${ref#refs/tags/}" | |
491 | # XXX: Rewrite tagged trees as well? | |
492 | if [ "$type" != "commit" -a "$type" != "tag" ]; then | |
493 | continue; | |
494 | fi | |
495 | ||
496 | if [ "$type" = "tag" ]; then | |
497 | # Dereference to a commit | |
498 | sha1t="$sha1" | |
7bd93c1c | 499 | sha1="$(git rev-parse -q "$sha1"^{commit})" || continue |
6f6826c5 JS |
500 | fi |
501 | ||
502 | [ -f "../map/$sha1" ] || continue | |
503 | new_sha1="$(cat "../map/$sha1")" | |
3addc94a JS |
504 | GIT_COMMIT="$sha1" |
505 | export GIT_COMMIT | |
8c1ce0f4 JS |
506 | new_ref="$(echo "$ref" | eval "$filter_tag_name")" || |
507 | die "tag name filter failed: $filter_tag_name" | |
6f6826c5 JS |
508 | |
509 | echo "$ref -> $new_ref ($sha1 -> $new_sha1)" | |
510 | ||
511 | if [ "$type" = "tag" ]; then | |
a9da1663 JS |
512 | new_sha1=$( ( printf 'object %s\ntype commit\ntag %s\n' \ |
513 | "$new_sha1" "$new_ref" | |
514 | git cat-file tag "$ref" | | |
1bf6551e | 515 | sed -n \ |
9524cf29 | 516 | -e '1,/^$/{ |
a9da1663 JS |
517 | /^object /d |
518 | /^type /d | |
519 | /^tag /d | |
9524cf29 | 520 | }' \ |
1bf6551e | 521 | -e '/^-----BEGIN PGP SIGNATURE-----/q' \ |
a9da1663 | 522 | -e 'p' ) | |
1bf6551e BC |
523 | git mktag) || |
524 | die "Could not create new tag object for $ref" | |
525 | if git cat-file tag "$ref" | \ | |
e1622bfc | 526 | sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1 |
1bf6551e BC |
527 | then |
528 | warn "gpg signature stripped from tag object $sha1t" | |
529 | fi | |
6f6826c5 JS |
530 | fi |
531 | ||
af580e9c JS |
532 | git update-ref "refs/tags/$new_ref" "$new_sha1" || |
533 | die "Could not write tag $new_ref" | |
6f6826c5 JS |
534 | done |
535 | fi | |
536 | ||
97276019 | 537 | cd "$orig_dir" |
6f6826c5 | 538 | rm -rf "$tempdir" |
6f6826c5 | 539 | |
def16e71 BC |
540 | trap - 0 |
541 | ||
9273b562 EK |
542 | unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE |
543 | test -z "$ORIG_GIT_DIR" || { | |
544 | GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR | |
545 | } | |
546 | test -z "$ORIG_GIT_WORK_TREE" || { | |
547 | GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" && | |
548 | export GIT_WORK_TREE | |
549 | } | |
550 | test -z "$ORIG_GIT_INDEX_FILE" || { | |
551 | GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" && | |
552 | export GIT_INDEX_FILE | |
553 | } | |
554 | ||
a4661b01 | 555 | if [ "$(is_bare_repository)" = false ]; then |
0ea29cce | 556 | git read-tree -u -m HEAD || exit |
a4661b01 | 557 | fi |
46eb449c | 558 | |
0ea29cce | 559 | exit 0 |