Merge branch 'jk/filter-branch-come-back-to-original' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Apr 2013 18:26:55 +0000 (11:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Apr 2013 18:26:55 +0000 (11:26 -0700)
* jk/filter-branch-come-back-to-original:
filter-branch: return to original dir after filtering

1  2 
git-filter-branch.sh
t/t7003-filter-branch.sh
diff --combined git-filter-branch.sh
index 53142492afcfb92f0453359af9a00a045c51e7e9,244253653db99ef1d41bfe2854be954bef47abe8..ac2a005fdb23c48d8451188ffd7b1c8194b0295f
@@@ -64,19 -64,37 +64,19 @@@ EO
  
  eval "$functions"
  
 -# When piped a commit, output a script to set the ident of either
 -# "author" or "committer
 +finish_ident() {
 +      # Ensure non-empty id name.
 +      echo "case \"\$GIT_$1_NAME\" in \"\") GIT_$1_NAME=\"\${GIT_$1_EMAIL%%@*}\" && export GIT_$1_NAME;; esac"
 +      # And make sure everything is exported.
 +      echo "export GIT_$1_NAME"
 +      echo "export GIT_$1_EMAIL"
 +      echo "export GIT_$1_DATE"
 +}
  
  set_ident () {
 -      lid="$(echo "$1" | tr "[A-Z]" "[a-z]")"
 -      uid="$(echo "$1" | tr "[a-z]" "[A-Z]")"
 -      pick_id_script='
 -              /^'$lid' /{
 -                      s/'\''/'\''\\'\'\''/g
 -                      h
 -                      s/^'$lid' \([^<]*\) <[^>]*> .*$/\1/
 -                      s/'\''/'\''\'\'\''/g
 -                      s/.*/GIT_'$uid'_NAME='\''&'\''; export GIT_'$uid'_NAME/p
 -
 -                      g
 -                      s/^'$lid' [^<]* <\([^>]*\)> .*$/\1/
 -                      s/'\''/'\''\'\'\''/g
 -                      s/.*/GIT_'$uid'_EMAIL='\''&'\''; export GIT_'$uid'_EMAIL/p
 -
 -                      g
 -                      s/^'$lid' [^<]* <[^>]*> \(.*\)$/@\1/
 -                      s/'\''/'\''\'\'\''/g
 -                      s/.*/GIT_'$uid'_DATE='\''&'\''; export GIT_'$uid'_DATE/p
 -
 -                      q
 -              }
 -      '
 -
 -      LANG=C LC_ALL=C sed -ne "$pick_id_script"
 -      # Ensure non-empty id name.
 -      echo "case \"\$GIT_${uid}_NAME\" in \"\") GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\" && export GIT_${uid}_NAME;; esac"
 +      parse_ident_from_commit author AUTHOR committer COMMITTER
 +      finish_ident AUTHOR
 +      finish_ident COMMITTER
  }
  
  USAGE="[--env-filter <command>] [--tree-filter <command>]
@@@ -199,6 -217,7 +199,7 @@@ t
        test -d "$tempdir" &&
                die "$tempdir already exists, please remove it"
  esac
+ orig_dir=$(pwd)
  mkdir -p "$tempdir/t" &&
  tempdir="$(cd "$tempdir"; pwd)" &&
  cd "$tempdir/t" &&
@@@ -206,7 -225,7 +207,7 @@@ workdir="$(pwd)" |
  die ""
  
  # Remove tempdir on exit
- trap 'cd ../..; rm -rf "$tempdir"' 0
+ trap 'cd "$orig_dir"; rm -rf "$tempdir"' 0
  
  ORIG_GIT_DIR="$GIT_DIR"
  ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
@@@ -302,8 -321,10 +303,8 @@@ while read commit parents; d
        git cat-file commit "$commit" >../commit ||
                die "Cannot read commit $commit"
  
 -      eval "$(set_ident AUTHOR <../commit)" ||
 -              die "setting author failed for commit $commit"
 -      eval "$(set_ident COMMITTER <../commit)" ||
 -              die "setting committer failed for commit $commit"
 +      eval "$(set_ident <../commit)" ||
 +              die "setting author/committer failed for commit $commit"
        eval "$filter_env" < /dev/null ||
                die "env filter failed: $filter_env"
  
@@@ -469,7 -490,7 +470,7 @@@ if [ "$filter_tag_name" ]; the
        done
  fi
  
- cd ../..
+ cd "$orig_dir"
  rm -rf "$tempdir"
  
  trap - 0
diff --combined t/t7003-filter-branch.sh
index 1e7a209efa715bc52d14d7f653ecfc13ffb5301f,782270204564adb4025089fd88b5049d1c713ece..9496736a89eb6b0b1ece64052cd2726c516c952b
@@@ -64,6 -64,20 +64,20 @@@ test_expect_success 'correct GIT_DIR wh
        grep drepo "$TRASHDIR/backup-refs"
  '
  
+ test_expect_success 'tree-filter works with -d' '
+       git init drepo-tree &&
+       (
+               cd drepo-tree &&
+               test_commit one &&
+               git filter-branch -d "$TRASHDIR/dfoo" \
+                       --tree-filter "echo changed >one.t" &&
+               echo changed >expect &&
+               git cat-file blob HEAD:one.t >actual &&
+               test_cmp expect actual &&
+               test_cmp one.t actual
+       )
+ '
  test_expect_success 'Fail if commit filter fails' '
        test_must_fail git filter-branch -f --commit-filter "exit 1" HEAD
  '
@@@ -167,11 -181,10 +181,11 @@@ test_expect_success 'author informatio
        test_tick &&
        GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
        git branch preserved-author &&
 -      git filter-branch -f --msg-filter "cat; \
 +      (sane_unset GIT_AUTHOR_NAME &&
 +       git filter-branch -f --msg-filter "cat; \
                        test \$GIT_COMMIT != $(git rev-parse master) || \
                        echo Hallo" \
 -              preserved-author &&
 +              preserved-author) &&
        test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
  '