set -- -h
fi
OPTS_SPEC="\
-git subtree split [options...] <--prefix=prefix> <commit...> -- <path>
+git subtree add <--prefix=prefix <commit>
+git subtree split [options...] <--prefix=prefix> <commit...>
git subtree merge
--
h,help show the help
command="$1"
shift
case "$command" in
- split|merge) ;;
+ add|merge) default= ;;
+ split) default="--default HEAD" ;;
*) die "Unknown command '$command'" ;;
esac
-revs=$(git rev-parse --default HEAD --revs-only "$@") || exit $?
+revs=$(git rev-parse $default --revs-only "$@") || exit $?
if [ -z "$prefix" ]; then
die "You must provide the --prefix option."
debug "quiet: {$quiet}"
debug "revs: {$revs}"
debug "dir: {$dir}"
+debug
cache_setup()
{
) || die "Can't copy commit $1"
}
+add_msg()
+{
+ dir="$1"
+ latest_old="$2"
+ latest_new="$3"
+ cat <<-EOF
+ Add '$dir/' from commit '$latest_new'
+
+ git-subtree-dir: $dir
+ git-subtree-mainline: $latest_old
+ git-subtree-split: $latest_new
+ EOF
+}
+
merge_msg()
{
dir="$1"
fi
}
+cmd_add()
+{
+ if [ -e "$dir" ]; then
+ die "'$dir' already exists. Cannot add."
+ fi
+ if ! git diff-index HEAD --exit-code --quiet; then
+ die "Working tree has modifications. Cannot add."
+ fi
+ if ! git diff-index --cached HEAD --exit-code --quiet; then
+ die "Index has modifications. Cannot add."
+ fi
+ set -- $revs
+ if [ $# -ne 1 ]; then
+ die "You must provide exactly one revision. Got: '$revs'"
+ fi
+ rev="$1"
+
+ debug "Adding $dir as '$rev'..."
+ git read-tree --prefix="$dir" $rev || exit $?
+ git checkout "$dir" || exit $?
+ tree=$(git write-tree) || exit $?
+
+ headrev=$(git rev-parse HEAD) || exit $?
+ if [ -n "$headrev" -a "$headrev" != "$rev" ]; then
+ headp="-p $headrev"
+ else
+ headp=
+ fi
+ commit=$(add_msg "$dir" "$headrev" "$rev" |
+ git commit-tree $tree $headp -p "$rev") || exit $?
+ git reset "$commit" || exit $?
+}
+
cmd_split()
{
debug "Splitting $dir..."