When calling stat, check for last modified time instead of last accessed.
[guilt.git] / regression / scaffold
blobd2c59853ce0c5ebb9144b9131585081adb8a39fc
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 UNAME_S=`uname -s`
21 # usage: die <msg>
22 function die
24         echo "Error: $@" >&2
25         exit 1
28 function replace_path
30         sed -e "s,$PWD,PATH,g" \
31             -e "s,$REG_DIR/\.\./,,g" \
32             -e "s,^Usage: guilt-,Usage: guilt ,g" \
33             -e "s,\.\.\. initial, initial,g" \
34             -e "s,^Already on\( branch\)\? [\"']\([^\"']*\)[\"']$,Already on \"\2\",g" \
35             -e "s,^Switched to branch [\"']\([^\"']*\)[\"'],Switched to branch \"\1\",g"
38 function filter_dd
40         sed -e 's:^\([0-9]*\) bytes (\([0-9]*\.[0-9]* .B\)) copied.*$:\1 bytes (\2) copied:'
43 # usage: cmd <cmd>..
44 function cmd
46         echo "% $@"
47         "$@" 2>&1 | replace_path && return 0
48         return 1
51 # usage: shouldfail <cmd>..
52 function shouldfail
54         echo "% $@"
55         (
56                 "$@" 2>&1 || return 0
57                 return 1
58         ) | replace_path
59         return $?
62 # usage: list_files
63 function list_files
65         (
66                 find .git/refs/patches -type f -exec dump_ref {} \; 2> /dev/null || true
67                 find .git/refs/patches -type d -exec dump_reg {} \; 2> /dev/null || true
68                 find .git/patches -exec dump_reg {} \;
69         ) | sort
72 function setup_git_repo
74         # set up the repo so we have something interesting to run guilt on
75         echo "abc" > def
76         git add def
77         git commit -s -m "initial" 2> /dev/null > /dev/null
78         # the commit should be d4850419ccc1146c7169f500725ce504b9774ed0
81 function setup_guilt_repo
83         mkdir -p .git/patches/master
85         # patch to modify a file
86         cp "$REG_DIR/data/modify.patch" .git/patches/master/modify
88         # patch to add a new file
89         cp "$REG_DIR/data/add.patch" .git/patches/master/add
91         # patch to remove an existing file
92         cp "$REG_DIR/data/remove.patch" .git/patches/master/remove
94         # patch to change a mode
95         cp "$REG_DIR/data/mode.patch" .git/patches/master/mode
97         # the series file of all the things
98         cp "$REG_DIR/data/series" .git/patches/master/series
100         # the status file
101         touch .git/patches/master/status
103         # the status file
104         touch .git/patches/master/status
106         touch -a -m -t "$TOUCH_DATE" .git/patches/master/modify
107         touch -a -m -t "$TOUCH_DATE" .git/patches/master/add
108         touch -a -m -t "$TOUCH_DATE" .git/patches/master/remove
109         touch -a -m -t "$TOUCH_DATE" .git/patches/master/mode
112 function reset_git_repo
114         git checkout master
116         git reset --hard d4850419ccc1146c7169f500725ce504b9774ed0
118         rm -rf .git/patches/
121 function setup_repo
123         setup_git_repo
124         setup_guilt_repo
127 function seq() {
128         if [ $UNAME_S = "Linux" ]
129         then
130                 `which seq` "$@"
131                 return $?
132         fi
133         declare incr n1 n2 num1 num2
134         if [[ $# -eq 1 ]]
135         then
136                 /usr/bin/jot $1
137         elif [[ $# -eq 2 ]]
138         then
139                 n1=$((${2} - ${1} + 1))
140                 n2=$1
141                 /usr/bin/jot $n1 $n2
142         elif [[ $# -eq 3 ]]
143         then
144                 num1=${1}
145                 incr=${2}
146                 num2=${3}
147                 # /usr/bin/awk -v n1=${num1} -v n2=${num2} -v add=${incr} 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed 's/.+e.+/0/'
148                 /usr/bin/awk -v n1=${num1} -v n2=${num2} -v add=${incr} 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/'
149         fi
150         return 0