chiark / gitweb /
tests/tests/quilt: Test series quiltification
[dgit.git] / tests / tartree-edit
1 #!/bin/sh
2 set -e
3 fail () { echo >&2 "$0: $*"; exit 1; }
4
5 case "$#.$1" in
6 2.edit|2.done)  mode="$1"; arg="$2" ;;
7 2.-*)           fail "no options understood"                    ;;
8 *)              fail "usage: tartree-edit edit|done DIRECTORY"  ;;
9 esac
10
11 case "$arg" in
12 *.tar)          base=${arg%.tar}                        ;;
13 *.edit)         base=${arg%.edit}                       ;;
14 *)              base=${arg}                             ;;
15 esac
16
17 tryat_pre () {
18         local b="$1"
19         rm -rf "$b.tmp"
20         if test -f "$b.tar" && test -f "$b.edit"; then
21                 echo "$b.edit exists, deleting possibly-obsolete $b.tar"
22                 rm "$b.tar"
23         fi
24 }
25
26 tryat_edit () {
27         local b="$1"
28         if test -d "$b.edit"; then
29                 echo "$b.edit already exists"
30                 exit 0
31         fi
32         if test -f "$b.tar"; then
33                 mkdir "$b.tmp"
34                 (set -e; cd "$b.tmp"; tar xf "$b.tar")
35                 mv "$b.tmp" "$b.edit"
36                 rm "$b.tar"
37                 echo "$b.edit ready"
38                 exit 0
39         fi
40 }
41
42 tryat_done () {
43         local b="$1"
44         if test -d "$b.edit"; then
45                 (set -e; cd "$b.edit"; tar cf "$b.tmp" *)
46                 mv "$b.tmp" "$b.tar"
47                 mv "$b.edit" "$b.tmp"
48                 rm -rf "$b.tmp"
49                 echo "$b.tar regenerated"
50                 exit 0
51         fi
52         if test -f "$b.tar"; then
53                 echo "$b.tar already exists and $b.edit doesn't"
54                 exit 0
55         fi
56 }
57
58 tryat () {
59         local b="$1"
60         if ! test -f "$b.tar" && ! test -d "$b.edit"; then
61                 return
62         fi
63         tryat_pre "$b"
64         tryat_$mode "$b"
65         fail "unexpected situation in $b.*"
66 }
67
68 case "$arg" in
69 /*)             tryat "$base"
70                 ;;
71 *)
72                 pwd=`pwd`
73                 tryat "$pwd/$base"
74                 tryat "$pwd/git-srcs/$base"
75                 tryat "$pwd/tests/git-srcs/$base"
76                 fail "could not find $base..."
77                 ;;
78 esac