Merge branch 'js/filter-branch-submodule'
authorJunio C Hamano <gitster@pobox.com>
Sat, 7 Feb 2009 19:09:48 +0000 (11:09 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 7 Feb 2009 19:09:48 +0000 (11:09 -0800)
* js/filter-branch-submodule:
filter-branch: do not consider diverging submodules a 'dirty worktree'
filter-branch: Fix fatal error on bare repositories

1  2 
git-filter-branch.sh
t/t7003-filter-branch.sh
diff --combined git-filter-branch.sh
index eb62f719b0ad1d015bb116e8447971c5fe7fdba6,0897b5971a770755527817d4cb3766d87ce5bebd..86eef562978f331f1d6e8f187dfc44e3fdd03e16
@@@ -40,16 -40,6 +40,16 @@@ skip_commit(
        done;
  }
  
 +# if you run 'git_commit_non_empty_tree "$@"' in a commit filter,
 +# it will skip commits that leave the tree untouched, commit the other.
 +git_commit_non_empty_tree()
 +{
 +      if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
 +              map "$3"
 +      else
 +              git commit-tree "$@"
 +      fi
 +}
  # override die(): this version puts in an extra line break, so that
  # the progress is still visible
  
@@@ -108,7 -98,7 +108,7 @@@ OPTIONS_SPEC
  . git-sh-setup
  
  if [ "$(is_bare_repository)" = false ]; then
-       git diff-files --quiet &&
+       git diff-files --ignore-submodules --quiet &&
        git diff-index --cached --quiet HEAD -- ||
        die "Cannot rewrite branch(es) with a dirty working directory."
  fi
@@@ -119,12 -109,11 +119,12 @@@ filter_tree
  filter_index=
  filter_parent=
  filter_msg=cat
 -filter_commit='git commit-tree "$@"'
 +filter_commit=
  filter_tag_name=
  filter_subdir=
  orig_namespace=refs/original/
  force=
 +prune_empty=
  while :
  do
        case "$1" in
                force=t
                continue
                ;;
 +      --prune-empty)
 +              shift
 +              prune_empty=t
 +              continue
 +              ;;
        -*)
                ;;
        *)
        esac
  done
  
 +case "$prune_empty,$filter_commit" in
 +,)
 +      filter_commit='git commit-tree "$@"';;
 +t,)
 +      filter_commit="$functions;"' git_commit_non_empty_tree "$@"';;
 +,*)
 +      ;;
 +*)
 +      die "Cannot set --prune-empty and --filter-commit at the same time"
 +esac
 +
  case "$force" in
  t)
        rm -rf "$tempdir"
@@@ -469,19 -442,20 +469,20 @@@ rm -rf "$tempdir
  
  trap - 0
  
+ unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
+ test -z "$ORIG_GIT_DIR" || {
+       GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
+ }
+ test -z "$ORIG_GIT_WORK_TREE" || {
+       GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
+       export GIT_WORK_TREE
+ }
+ test -z "$ORIG_GIT_INDEX_FILE" || {
+       GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
+       export GIT_INDEX_FILE
+ }
  if [ "$(is_bare_repository)" = false ]; then
-       unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
-       test -z "$ORIG_GIT_DIR" || {
-               GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
-       }
-       test -z "$ORIG_GIT_WORK_TREE" || {
-               GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
-               export GIT_WORK_TREE
-       }
-       test -z "$ORIG_GIT_INDEX_FILE" || {
-               GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
-               export GIT_INDEX_FILE
-       }
        git read-tree -u -m HEAD
  fi
  
diff --combined t/t7003-filter-branch.sh
index 8537bf91606282161ab92b6f2f7367c9a3c016fc,6a9936e5c45a973f2fd64a2fe20463497f9564eb..cb0474336d66302d9c7cf003bcdeadacb789aa8a
@@@ -39,7 -39,9 +39,9 @@@ test_expect_success 'result is really i
  '
  
  test_expect_success 'rewrite bare repository identically' '
-       (git config core.bare true && cd .git && git filter-branch branch)
+       (git config core.bare true && cd .git &&
+        git filter-branch branch > filter-output 2>&1 &&
+       ! fgrep fatal filter-output)
  '
  git config core.bare false
  test_expect_success 'result is really identical' '
@@@ -262,12 -264,4 +264,12 @@@ test_expect_success 'Tag name filterin
        test_cmp expect actual
  '
  
 +test_expect_success 'Prune empty commits' '
 +      git rev-list HEAD > expect &&
 +      make_commit to_remove &&
 +      git filter-branch -f --index-filter "git update-index --remove to_remove" --prune-empty HEAD &&
 +      git rev-list HEAD > actual &&
 +      test_cmp expect actual
 +'
 +
  test_done