chiark / gitweb /
tests: git-repo-edit: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 Feb 2014 18:35:44 +0000 (18:35 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 5 Mar 2014 18:29:06 +0000 (18:29 +0000)
tests/gitrepo-edit [new file with mode: 0755]
tests/lib

diff --git a/tests/gitrepo-edit b/tests/gitrepo-edit
new file mode 100755 (executable)
index 0000000..97bbd2c
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/sh
+set -e
+fail () { echo >&2 "$0: $*"; exit 1; }
+
+case "$1" in
+edit|done) mode=$1
+fi
+
+case "$*.$1" in
+1.-*)  fail "no options understood"            ;;
+1.*)   arg="$1"; shift                         ;;
+*)     fail "need one arg"                     ;;
+esac
+
+case "$arg" in
+*.git.tar)     base=${arg%.tar}                        ;;
+*.git)         base=${arg}                             ;;
+*)             fail "arg must end in .git[.tar]"       ;;
+esac
+
+tryat_pre () {
+       local b="$1"
+       rm -rf "$b.tmp"
+       if test -f "$b.tar" && test -f "$b.edit"; then
+               echo "$b.edit exists, deleting possibly-obsolete $b.tar"
+               rm "$b.tar"
+       fi
+}
+
+tryat_edit () {
+       local b="$1"
+       if test -d "$b.edit"; then
+               echo "$b.edit already exists"
+               exit 0
+       fi
+       if test -f "$b.tar"; then
+               mkdir "$b.tmp"
+               (set -e; cd "$b.tmp"; tar xf "$b.tar")
+               mv "$b.tmp/$b" "$b.edit"
+               rm "$b.tar"
+               rm -rf "$b.tmp"
+               echo "$b.edit ready"
+               exit 0
+       fi
+}
+
+tryat_done () {
+       local b="$1"
+       if test -d "$b.edit"; then
+               mkdir "$b.tmp"
+               cp -al "$b.edit" "$b.tmp/$b"
+               (set -e; cd "$b.tmp"; tar cf "$b.tmp/tar")
+               mv "$b.tmp/tar" "$b.tar"
+               rm -rf "$b.tmp"
+               mv "$b.edit" "$b.tmp"
+               rm -rf "$b.tmp"
+               echo "$b.tar regenerated"
+               exit 0
+       fi
+       if test -f "$b.tar"; then
+               echo "$b.tar already exists and $b.edit doesn't"
+               exit 0
+       fi
+}
+
+tryat () {
+       local b="$1"
+       if ! test -f "$b.tar" && ! test -f "$b.edit"; then
+               return
+       fi
+       tryat_pre "$b"
+       tryat_$mode "$b"
+       fail "unexpected situation in $b.*"
+}
+
+case "$arg" in
+/*)            tryat "$base"
+               ;;
+*)
+               pwd=`pwd`
+               tryat "$pwd/$base"
+               tryat "$pwd/git-srcs/$base"
+               tryat "$pwd/tests/git-srcs/$base"
+               ;;
+esac
index 0630f1d..fb6b2fc 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -48,7 +48,12 @@ t-git () {
        p=$1
        v=$2
        mkdir -p $tmp/git
-       (set -e; cd $tmp/git; tar xf $troot/git-srcs/${p}_$v.git.tar)
+       local gs=$troot/git-srcs/${p}_$v.git
+       if test -f $gs.edit; then
+               cp -al $gs.edit $tmp/git/${p}.git
+       else
+               (set -e; cd $tmp/git; tar xf $gs.tar)
+       fi
 }
 
 t-git-none () {