filter-branch: fix errors caused by refs that point at non-committish
"git filter-branch -- --all" prints error messages when processing refs that point at objects that are not committish. Such refs can be created by "git replace" with trees or blobs. And also "git tag" with trees or blobs can create such refs. Filter these problematic refs out early, before they are seen by the logic to see which refs have been modified and which have been left intact (which is where the unwanted error messages come from), and warn that these refs are left unwritten while doing so. Signed-off-by: Yuki Kokubun <orga.chem.job@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Yuki Kokubun committed
Mar 25, 2018 at 16:54 UTC
f78ab355e7d91c70faf41ddad9577cffc3b4ee60
2 files changed
+26
-2
git-filter-branch.sh
+12
-2
@@ -251,8 +251,18 @@ done < "$tempdir"/backup-refs
251
252
# The refs should be updated if their heads were rewritten
253
git rev-parse --no-flags --revs-only --symbolic-full-name \
254
- --default HEAD "$@" > "$tempdir"/raw-heads || exit
255
-sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
254
+ --default HEAD "$@" > "$tempdir"/raw-refs || exit
255
+while read ref
256
+do
257
+ case "$ref" in ^?*) continue ;; esac
258
+
259
+ if git rev-parse --verify "$ref"^0 >/dev/null 2>&1
260
+ then
261
+ echo "$ref"
262
+ else
263
+ warn "WARNING: not rewriting '$ref' (not a committish)"
264
+ fi
265
+done >"$tempdir"/heads <"$tempdir"/raw-refs
266
267
test -s "$tempdir"/heads ||
268
die "You must specify a ref to rewrite."
t/t7003-filter-branch.sh
+14
@@ -470,4 +470,18 @@ test_expect_success 'tree-filter deals with object name vs pathname ambiguity' '
470
git show HEAD:$ambiguous
471
'
472
473
+test_expect_success 'rewrite repository including refs that point at non-commit object' '
474
+ test_when_finished "git reset --hard original" &&
475
+ tree=$(git rev-parse HEAD^{tree}) &&
476
+ test_when_finished "git replace -d $tree" &&
477
+ echo A >new &&
478
+ git add new &&
479
+ new_tree=$(git write-tree) &&
480
+ git replace $tree $new_tree &&
481
+ git tag -a -m "tag to a tree" treetag $new_tree &&
482
+ git reset --hard HEAD &&
483
+ git filter-branch -f -- --all >filter-output 2>&1 &&
484
+ ! fgrep fatal filter-output
485
+'
486
+
487
test_done