case "$#.$1" in
2.edit|2.done) mode="$1"; arg="$2" ;;
-2.-*) fail "no options understood" ;;
-*) fail "usage: tartree-edit edit|done DIRECTORY" ;;
+3.gitfetchinfo) mode="$1"; arg="$2"; remote="$3" ;;
+?.-*) fail "no options understood" ;;
+*) fail "usage:
+ tartree-edit edit|done DIRECTORY|TARBALL
+ tartree-edit gitfetchinfo DIRECTORY|TARBALL REMOTE" ;;
esac
case "$arg" in
fi
}
+gitfetchinfo_perhaps_commit () {
+ local m="$1"
+ set +e
+ git diff --cached --quiet --exit-code HEAD
+ local rc=$?
+ set -e
+ case "$rc" in
+ 0) return ;;
+ 1) git commit --allow-empty --author='tartree-edit <>' -m "$m" ;;
+ *) fail "git diff failed ($rc)" ;;
+ esac
+}
+
+tryat_gitfetchinfo () {
+ local wd=$(pwd)
+ case "$wd" in
+ *.edit) fail "bad idea to run gitfetchinfo into a .edit tree!" ;;
+ esac
+ local play=.git/tartree-edit-work
+ rm -rf $play
+ mkdir $play
+ if test -d "$b.edit"; then
+ cp -a "$b.edit"/. "$play"/.
+ else
+ exec 3<"$b.tar"
+ tar -C $play -f - <&3 -x
+ exec 3<&-
+ fi
+ local innerwd=$play/*
+ git remote remove "$remote" 2>/dev/null ||:
+ git remote add "$remote" $innerwd
+ git fetch --no-tags -p "$remote" \
+ +"HEAD:refs/remotes/$remote/HEAD"
+ cd $innerwd
+ git checkout -b WORKTREE
+ gitfetchinfo_perhaps_commit INDEX
+ git add -Af .
+ gitfetchinfo_perhaps_commit WORKTREE
+ cd ../../..
+ git fetch --no-tags "$remote" --refmap \
+ +"refs/*:refs/remotes/$remote/*" \
+ +"refs/*:refs/remotes/$remote/*"
+ exit 0
+}
+
tryat_done () {
local b="$1"
if test -d "$b.edit"; then