regression: test the new init options
[guilt.git] / regression / scaffold
blob6a1cef8a0a3afa64488db1bff71074b7b108021f
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,REGDIR,g"
32 # usage: cmd <cmd>..
33 function cmd
35         echo "% $@"
36         "$@" 2>&1 | replace_path && return 0
37         return 1
40 # usage: shouldfail <cmd>..
41 function shouldfail
43         echo "% $@"
44         (
45                 "$@" 2>&1 || return 0
46                 return 1
47         ) | replace_path
48         return $?
51 # usage: list_files
52 function list_files
54         (
55                 find .git/refs/patches -type f -exec dump_ref {} \; 2> /dev/null || true
56                 find .git/refs/patches -type d -exec dump_reg {} \; 2> /dev/null || true
57                 find .git/patches -exec dump_reg {} \;
58         ) | sort
61 function setup_git_repo
63         # set up the repo so we have something interesting to run guilt on
64         echo "abc" > def
65         git-add def
66         git-commit -s -m "initial" 2> /dev/null > /dev/null
67         # the commit should be d4850419ccc1146c7169f500725ce504b9774ed0
70 function setup_guilt_repo
72         mkdir -p .git/patches/master
74         # patch to modify a file
75         cp "$REG_DIR/data/modify.patch" .git/patches/master/modify
77         # patch to add a new file
78         cp "$REG_DIR/data/add.patch" .git/patches/master/add
80         # patch to remove an existing file
81         cp "$REG_DIR/data/remove.patch" .git/patches/master/remove
83         # patch to change a mode
84         cp "$REG_DIR/data/mode.patch" .git/patches/master/mode
86         # the series file of all the things
87         cp "$REG_DIR/data/series" .git/patches/master/series
89         # the status file
90         touch .git/patches/master/status
92         # the status file
93         touch .git/patches/master/status
95         touch -a -m -t "$TOUCH_DATE" .git/patches/master/modify
96         touch -a -m -t "$TOUCH_DATE" .git/patches/master/add
97         touch -a -m -t "$TOUCH_DATE" .git/patches/master/remove
98         touch -a -m -t "$TOUCH_DATE" .git/patches/master/mode
101 function reset_git_repo
103         git-checkout master
105         git-reset --hard d4850419ccc1146c7169f500725ce504b9774ed0
107         rm -rf .git/patches/
110 function setup_repo
112         setup_git_repo
113         setup_guilt_repo