diff --git i/git-subtree.sh w/git-subtree.sh index 781eef3..7706d72 100755 --- i/git-subtree.sh +++ w/git-subtree.sh @@ -27,6 +27,7 @@ onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD options for 'add', 'merge', 'pull' and 'push' squash merge subtree changes as a single commit +prune prune history " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) @@ -44,6 +45,7 @@ rejoin= ignore_joins= annotate= squash= +prune= message= debug() @@ -92,6 +94,8 @@ while [ $# -gt 0 ]; do --no-ignore-joins) ignore_joins= ;; --squash) squash=1 ;; --no-squash) squash= ;; + --prune) prune=1;; + --no-prune) prune=;; --) break ;; *) die "Unexpected option: $opt" ;; esac @@ -110,7 +114,7 @@ if [ -z "$prefix" ]; then fi case "$command" in - add) [ -e "$prefix" ] && + add) [ -e "$prefix" -a -z "$prune" ] && die "prefix '$prefix' already exists." ;; *) [ -e "$prefix" ] || die "'$prefix' does not exist; use 'git subtree add'" ;; @@ -359,6 +363,17 @@ squash_msg() echo "git-subtree-split: $newsub" } +prune_msg() +{ + dir="$1" + newsub="$2" + + git show -s --pretty="tformat:Subtree '$dir/': %h %s" $newsub + echo + echo "git-subtree-dir: $dir" + echo "git-subtree-split: $newsub" +} + toptree_for_commit() { commit="$1" @@ -464,7 +479,7 @@ ensure_clean() cmd_add() { - if [ -e "$dir" ]; then + if [ -e "$dir" -a -z "$prune" ]; then die "'$dir' already exists. Cannot add." fi @@ -498,6 +513,10 @@ cmd_add_commit() rev="$1" debug "Adding $dir as '$rev'..." + if [ -d "$dir" ]; then + #TODO: write it with plumbing commands + git rm -r -q $dir + fi git read-tree --prefix="$dir" $rev || exit $? git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? @@ -513,6 +532,9 @@ cmd_add_commit() rev=$(new_squash_commit "" "" "$rev") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? + elif [ -n "$prune" ]; then + commit=$(prune_msg "$dir" "$rev" | + git commit-tree $tree -p $headrev) || exit $? else commit=$(add_msg "$dir" "$headrev" "$rev" | git commit-tree $tree $headp -p "$rev") || exit $?