Guilt v0.32-rc2
[guilt.git] / regression / scaffold
blob89e1c9ffe2c285b22136a48aedc06c1444b14bcc
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" \
30             -e "s,\.\.\. initial, initial,g" \
31             -e "s,^Already on branch,Already on,g"
34 function filter_dd
36         sed -e 's:^\([0-9]*\) bytes (\([0-9]*\.[0-9]* .B\)) copied.*$:\1 bytes (\2) copied:'
39 # usage: cmd <cmd>..
40 function cmd
42         echo "% $@"
43         "$@" 2>&1 | replace_path && return 0
44         return 1
47 # usage: shouldfail <cmd>..
48 function shouldfail
50         echo "% $@"
51         (
52                 "$@" 2>&1 || return 0
53                 return 1
54         ) | replace_path
55         return $?
58 # usage: list_files
59 function list_files
61         (
62                 find .git/refs/patches -type f -exec dump_ref {} \; 2> /dev/null || true
63                 find .git/refs/patches -type d -exec dump_reg {} \; 2> /dev/null || true
64                 find .git/patches -exec dump_reg {} \;
65         ) | sort
68 function setup_git_repo
70         # set up the repo so we have something interesting to run guilt on
71         echo "abc" > def
72         git add def
73         git commit -s -m "initial" 2> /dev/null > /dev/null
74         # the commit should be d4850419ccc1146c7169f500725ce504b9774ed0
77 function setup_guilt_repo
79         mkdir -p .git/patches/master
81         # patch to modify a file
82         cp "$REG_DIR/data/modify.patch" .git/patches/master/modify
84         # patch to add a new file
85         cp "$REG_DIR/data/add.patch" .git/patches/master/add
87         # patch to remove an existing file
88         cp "$REG_DIR/data/remove.patch" .git/patches/master/remove
90         # patch to change a mode
91         cp "$REG_DIR/data/mode.patch" .git/patches/master/mode
93         # the series file of all the things
94         cp "$REG_DIR/data/series" .git/patches/master/series
96         # the status file
97         touch .git/patches/master/status
99         # the status file
100         touch .git/patches/master/status
102         touch -a -m -t "$TOUCH_DATE" .git/patches/master/modify
103         touch -a -m -t "$TOUCH_DATE" .git/patches/master/add
104         touch -a -m -t "$TOUCH_DATE" .git/patches/master/remove
105         touch -a -m -t "$TOUCH_DATE" .git/patches/master/mode
108 function reset_git_repo
110         git checkout master
112         git reset --hard d4850419ccc1146c7169f500725ce504b9774ed0
114         rm -rf .git/patches/
117 function setup_repo
119         setup_git_repo
120         setup_guilt_repo