chiark / gitweb /
Test suite: Provide `tartree-edit gitfetchinfo'
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jul 2016 09:23:01 +0000 (10:23 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jul 2016 09:23:06 +0000 (10:23 +0100)
Help with comparing different test case git working tree tarballs.

debian/changelog
tests/tartree-edit

index 8d717fd..baf668a 100644 (file)
@@ -51,6 +51,8 @@ dgit (1.5~~) unstable; urgency=medium
     zealot is very slow and we need to give the other processes time
     to rollback and release the lock.
   * Test quilt single-debian-patch.
+  * Provide `tartree-edit gitfetchinfo' to help with comparing
+    different test case git working tree tarballs.
 
  --
 
index 2e0c017..14eec68 100755 (executable)
@@ -4,8 +4,11 @@ fail () { echo >&2 "$0: $*"; exit 1; }
 
 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
@@ -39,6 +42,51 @@ tryat_edit () {
        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