From: Junio C Hamano Date: Sat, 7 Feb 2009 19:09:48 +0000 (-0800) Subject: Merge branch 'js/filter-branch-submodule' X-Git-Tag: v1.6.2-rc0~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/df4364a42981dec067dbacfd6371d4ca910df48e?hp=-c Merge branch 'js/filter-branch-submodule' * js/filter-branch-submodule: filter-branch: do not consider diverging submodules a 'dirty worktree' filter-branch: Fix fatal error on bare repositories --- df4364a42981dec067dbacfd6371d4ca910df48e diff --combined git-filter-branch.sh index eb62f719b0,0897b5971a..86eef56297 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@@ -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 @@@ -137,11 -126,6 +137,11 @@@ force=t continue ;; + --prune-empty) + shift + prune_empty=t + continue + ;; -*) ;; *) @@@ -192,17 -176,6 +192,17 @@@ 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 8537bf9160,6a9936e5c4..cb0474336d --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@@ -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