select/guard: fixed bashism
[guilt.git] / regression / scaffold
blobb8addad5f79f01386cd61f77f02dbad24cf24285
1 if [ -z "$REG_DIR" ]; then
2         echo "ERROR: You cannot run tests by hand" >&2
3         exit 2
4 fi
6 set -e
8 export PATH=$PWD/..:$PATH
10 export TZ="UTC"
11 export TOUCH_DATE="200701010000.00"
12 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 UTC"
13 export GIT_COMMITTER_DATE="2007-01-01 00:00:00 UTC"
14 export GIT_AUTHOR_NAME="Author Name"
15 export GIT_AUTHOR_EMAIL="author@email"
16 export GIT_COMMITTER_NAME="Commiter Name"
17 export GIT_COMMITTER_EMAIL="commiter@email"
19 # usage: die <msg>
20 function die
22         echo "Error: $@" >&2
23         exit 1
26 function replace_path
28         sed -e "s,$PWD,PATH,g" \
29             -e "s,$REG_DIR/\.\./,,g" \
30             -e "s,^Usage: guilt-,Usage: guilt ,g" \
31             -e "s,\.\.\. initial, initial,g" \
32             -e "s,^Already on\( branch\)\? [\"']\([^\"']*\)[\"']$,Already on \"\2\",g" \
33             -e "s,^Switched to branch [\"']\([^\"']*\)[\"'],Switched to branch \"\1\",g"
36 function filter_dd
38         sed -e 's:^\([0-9]*\) bytes (\([0-9]*\.[0-9]* .B\)) copied.*$:\1 bytes (\2) copied:'
41 # usage: cmd <cmd>..
42 function cmd
44         echo "% $@"
45         "$@" 2>&1 | replace_path && return 0
46         return 1
49 # usage: shouldfail <cmd>..
50 function shouldfail
52         echo "% $@"
53         (
54                 "$@" 2>&1 || return 0
55                 return 1
56         ) | replace_path
57         return $?
60 # usage: list_files
61 function list_files
63         (
64                 find .git/refs/patches -type f -exec dump_ref {} \; 2> /dev/null || true
65                 find .git/refs/patches -type d -exec dump_reg {} \; 2> /dev/null || true
66                 find .git/patches -exec dump_reg {} \;
67         ) | sort
70 function setup_git_repo
72         # set up the repo so we have something interesting to run guilt on
73         echo "abc" > def
74         git add def
75         git commit -s -m "initial" 2> /dev/null > /dev/null
76         # the commit should be d4850419ccc1146c7169f500725ce504b9774ed0
79 function setup_guilt_repo
81         mkdir -p .git/patches/master
83         # patch to modify a file
84         cp "$REG_DIR/data/modify.patch" .git/patches/master/modify
86         # patch to add a new file
87         cp "$REG_DIR/data/add.patch" .git/patches/master/add
89         # patch to remove an existing file
90         cp "$REG_DIR/data/remove.patch" .git/patches/master/remove
92         # patch to change a mode
93         cp "$REG_DIR/data/mode.patch" .git/patches/master/mode
95         # the series file of all the things
96         cp "$REG_DIR/data/series" .git/patches/master/series
98         # the status file
99         touch .git/patches/master/status
101         # the status file
102         touch .git/patches/master/status
104         touch -a -m -t "$TOUCH_DATE" .git/patches/master/modify
105         touch -a -m -t "$TOUCH_DATE" .git/patches/master/add
106         touch -a -m -t "$TOUCH_DATE" .git/patches/master/remove
107         touch -a -m -t "$TOUCH_DATE" .git/patches/master/mode
110 function reset_git_repo
112         git checkout master
114         git reset --hard d4850419ccc1146c7169f500725ce504b9774ed0
116         rm -rf .git/patches/
119 function setup_repo
121         setup_git_repo
122         setup_guilt_repo