chiark / gitweb /
tests: gitrepo-edit: wip, before new layout
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 Feb 2014 15:34:51 +0000 (15:34 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 5 Mar 2014 18:29:06 +0000 (18:29 +0000)
tests/gitrepo-edit

index 97bbd2c..27be703 100755 (executable)
@@ -2,18 +2,15 @@
 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"                     ;;
+case "$#.$1" in
+2.edit|2.done) mode="$1"; arg="$2" ;;
+2.-*)          fail "no options understood"                    ;;
+*)             fail "usage: gitrepo-edit edit|done DIRECTORY"  ;;
 esac
 
 case "$arg" in
 *.git.tar)     base=${arg%.tar}                        ;;
+*.git.edit)    base=${arg%.edit}                       ;;
 *.git)         base=${arg}                             ;;
 *)             fail "arg must end in .git[.tar]"       ;;
 esac
@@ -29,6 +26,7 @@ tryat_pre () {
 
 tryat_edit () {
        local b="$1"
+       local i="$2"
        if test -d "$b.edit"; then
                echo "$b.edit already exists"
                exit 0
@@ -36,7 +34,7 @@ tryat_edit () {
        if test -f "$b.tar"; then
                mkdir "$b.tmp"
                (set -e; cd "$b.tmp"; tar xf "$b.tar")
-               mv "$b.tmp/$b" "$b.edit"
+               mv "$b.tmp/$i" "$b.edit"
                rm "$b.tar"
                rm -rf "$b.tmp"
                echo "$b.edit ready"
@@ -46,10 +44,11 @@ tryat_edit () {
 
 tryat_done () {
        local b="$1"
+       local i="$2"
        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")
+               cp -al "$b.edit" "$b.tmp/$i"
+               (set -e; cd "$b.tmp"; tar cf "$b.tmp/tar $i")
                mv "$b.tmp/tar" "$b.tar"
                rm -rf "$b.tmp"
                mv "$b.edit" "$b.tmp"
@@ -65,11 +64,13 @@ tryat_done () {
 
 tryat () {
        local b="$1"
+       local i="${b##*/}"
+       case "$i" in *_*.git) i="${i%_*.git}.git";; esac
        if ! test -f "$b.tar" && ! test -f "$b.edit"; then
                return
        fi
-       tryat_pre "$b"
-       tryat_$mode "$b"
+       tryat_pre "$b" "$i"
+       tryat_$mode "$b" "$i"
        fail "unexpected situation in $b.*"
 }
 
@@ -81,5 +82,6 @@ case "$arg" in
                tryat "$pwd/$base"
                tryat "$pwd/git-srcs/$base"
                tryat "$pwd/tests/git-srcs/$base"
+               fail "could not find $base..."
                ;;
 esac