Merge branch 'yk/filter-branch-non-committish-refs'
authorJunio C Hamano <gitster@pobox.com>
Tue, 10 Apr 2018 07:28:23 +0000 (16:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Apr 2018 07:28:23 +0000 (16:28 +0900)
when refs that do not point at committish are given, "git
filter-branch" gave a misleading error messages. This has been
corrected.

* yk/filter-branch-non-committish-refs:
filter-branch: fix errors caused by refs that point at non-committish

1  2 
git-filter-branch.sh
diff --combined git-filter-branch.sh
index 2587a01b9b4fa0344c695cb635e6eed26257e9f8,41efecb284b034920b0a672be0d333a4c85189ba..64f21547c1ab99ef3ad98d57fe0fbadff9621838
@@@ -251,8 -251,18 +251,18 @@@ done < "$tempdir"/backup-ref
  
  # The refs should be updated if their heads were rewritten
  git rev-parse --no-flags --revs-only --symbolic-full-name \
-       --default HEAD "$@" > "$tempdir"/raw-heads || exit
- sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
+       --default HEAD "$@" > "$tempdir"/raw-refs || exit
+ while read ref
+ do
+       case "$ref" in ^?*) continue ;; esac
+       if git rev-parse --verify "$ref"^0 >/dev/null 2>&1
+       then
+               echo "$ref"
+       else
+               warn "WARNING: not rewriting '$ref' (not a committish)"
+       fi
+ done >"$tempdir"/heads <"$tempdir"/raw-refs
  
  test -s "$tempdir"/heads ||
        die "You must specify a ref to rewrite."
@@@ -310,7 -320,7 +320,7 @@@ git rev-list --reverse --topo-order --d
        die "Could not get the commits"
  commits=$(wc -l <../revs | tr -d " ")
  
 -test $commits -eq 0 && die "Found nothing to rewrite"
 +test $commits -eq 0 && die_with_status 2 "Found nothing to rewrite"
  
  # Rewrite the commits
  report_progress ()
@@@ -627,12 -637,12 +637,12 @@@ the
                                print H "$_:$f\n" or die;
                        }
                        close(H) or die;' || die "Unable to save state")
 -      state_tree=$(/bin/echo -e "100644 blob $state_blob\tfilter.map" | git mktree)
 +      state_tree=$(printf '100644 blob %s\tfilter.map\n' "$state_blob" | git mktree)
        if test -n "$state_commit"
        then
 -              state_commit=$(/bin/echo "Sync" | git commit-tree "$state_tree" -p "$state_commit")
 +              state_commit=$(echo "Sync" | git commit-tree "$state_tree" -p "$state_commit")
        else
 -              state_commit=$(/bin/echo "Sync" | git commit-tree "$state_tree" )
 +              state_commit=$(echo "Sync" | git commit-tree "$state_tree" )
        fi
        git update-ref "$state_branch" "$state_commit"
  fi