debian/rules should be producing architecture independent packages
[stgit/dwhite.git] / t / t3300-edit.sh
blob5772e486be13527a3becdbeaf0299944a829cdbe
1 #!/bin/sh
2 test_description='Test "stg edit"'
4 . ./test-lib.sh
6 test_expect_success 'Setup' '
7 printf "000\n111\n222\n333\n" >> foo &&
8 git add foo &&
9 git commit -m "Initial commit" &&
10 sed -i "s/000/000xx/" foo &&
11 git commit -a -m "First change" &&
12 sed -i "s/111/111yy/" foo &&
13 git commit -a -m "Second change" &&
14 sed -i "s/222/222zz/" foo &&
15 git commit -a -m "Third change" &&
16 sed -i "s/333/333zz/" foo &&
17 git commit -a -m "Fourth change" &&
18 stg init &&
19 stg uncommit -n 4 p &&
20 stg pop -n 2 &&
21 stg hide p4 &&
22 test "$(echo $(stg series --all))" = "+ p1 > p2 - p3 ! p4"
25 # Commit parse functions.
26 msg () { git cat-file -p $1 | sed '1,/^$/d' | tr '\n' / | sed 's,/*$,,' ; }
27 auth () { git log -n 1 --pretty=format:"%an, %ae" $1 ; }
28 date () { git log -n 1 --pretty=format:%ai $1 ; }
30 test_expect_success 'Edit message of top patch' '
31 test "$(msg HEAD)" = "Second change" &&
32 stg edit p2 -m "Second change 2" &&
33 test "$(msg HEAD)" = "Second change 2"
36 test_expect_success 'Edit message of non-top patch' '
37 test "$(msg HEAD^)" = "First change" &&
38 stg edit p1 -m "First change 2" &&
39 test "$(msg HEAD^)" = "First change 2"
42 test_expect_success 'Edit message of unapplied patch' '
43 test "$(msg $(stg id p3))" = "Third change" &&
44 stg edit p3 -m "Third change 2" &&
45 test "$(msg $(stg id p3))" = "Third change 2"
48 test_expect_success 'Edit message of hidden patch' '
49 test "$(msg $(stg id p4))" = "Fourth change" &&
50 stg edit p4 -m "Fourth change 2" &&
51 test "$(msg $(stg id p4))" = "Fourth change 2"
54 test_expect_success 'Set patch message with --file <file>' '
55 test "$(msg HEAD)" = "Second change 2" &&
56 echo "Pride or Prejudice" > commitmsg &&
57 stg edit p2 -f commitmsg &&
58 test "$(msg HEAD)" = "Pride or Prejudice"
61 test_expect_success 'Set patch message with --file -' '
62 echo "Pride and Prejudice" | stg edit p2 -f - &&
63 test "$(msg HEAD)" = "Pride and Prejudice"
66 ( printf 'From: A U Thor <author@example.com>\nDate: <omitted>'
67 printf '\n\nPride and Prejudice' ) > expected-tmpl
68 omit_date () { sed "s/^Date:.*$/Date: <omitted>/" ; }
70 test_expect_success 'Save template to file' '
71 stg edit --save-template saved-tmpl p2 &&
72 omit_date < saved-tmpl > saved-tmpl-d &&
73 test_cmp expected-tmpl saved-tmpl-d
76 test_expect_success 'Save template to stdout' '
77 stg edit --save-template - p2 > saved-tmpl2 &&
78 omit_date < saved-tmpl2 > saved-tmpl2-d &&
79 test_cmp expected-tmpl saved-tmpl2-d
82 # Test the various ways of invoking the interactive editor. The
83 # preference order should be
85 # 1. GIT_EDITOR
86 # 2. stgit.editor (legacy)
87 # 3. core.editor
88 # 4. VISUAL
89 # 5. EDITOR
90 # 6. vi
92 mkeditor ()
94 cat > "$1" <<EOF
95 #!/bin/sh
96 printf "\n$1\n" >> "\$1"
97 EOF
98 chmod a+x "$1"
101 mkeditor vi
102 test_expect_failure 'Edit commit message interactively (vi)' '
103 m=$(msg HEAD) &&
104 PATH=.:$PATH stg edit p2 &&
105 test "$(msg HEAD)" = "$m/vi"
108 mkeditor e1
109 test_expect_success 'Edit commit message interactively (EDITOR)' '
110 m=$(msg HEAD) &&
111 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
112 echo $m && echo $(msg HEAD) &&
113 test "$(msg HEAD)" = "$m/e1"
116 mkeditor e2
117 test_expect_failure 'Edit commit message interactively (VISUAL)' '
118 m=$(msg HEAD) &&
119 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
120 test "$(msg HEAD)" = "$m/e2"
123 mkeditor e3
124 test_expect_failure 'Edit commit message interactively (core.editor)' '
125 m=$(msg HEAD) &&
126 git config core.editor e3 &&
127 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
128 test "$(msg HEAD)" = "$m/e3"
131 mkeditor e4
132 test_expect_success 'Edit commit message interactively (stgit.editor)' '
133 m=$(msg HEAD) &&
134 git config stgit.editor e4 &&
135 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
136 test "$(msg HEAD)" = "$m/e4"
139 mkeditor e5
140 test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '
141 m=$(msg HEAD) &&
142 GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
143 test "$(msg HEAD)" = "$m/e5"
146 rm -f vi e1 e2 e3 e4 e5
147 git config --unset core.editor
148 git config --unset stgit.editor
150 mkeditor twoliner
151 test_expect_failure 'Both noninterative and interactive editing' '
152 EDITOR=./twoliner stg edit -e -m "oneliner" p2 &&
153 test "$(msg HEAD)" = "oneliner/twoliner"
155 rm -f twoliner
157 cat > diffedit <<EOF
158 #!/bin/sh
159 sed -i 's/111yy/111YY/' "\$1"
161 chmod a+x diffedit
162 test_expect_success 'Edit patch diff' '
163 EDITOR=./diffedit stg edit -d p2 &&
164 test "$(grep 111 foo)" = "111YY"
166 rm -f diffedit
168 test_expect_success 'Sign a patch' '
169 m=$(msg HEAD) &&
170 stg edit --sign p2 &&
171 test "$(msg HEAD)" = "$m//Signed-off-by: C O Mitter <committer@example.com>"
174 test_expect_success 'Acknowledge a patch' '
175 m=$(msg HEAD^) &&
176 stg edit --ack p1 &&
177 test "$(msg HEAD^)" = "$m//Acked-by: C O Mitter <committer@example.com>"
180 test_expect_success 'Set author' '
181 stg edit p2 --author "Jane Austin <jaustin@example.com>" &&
182 test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
185 test_expect_success 'Fail to set broken author' '
186 command_error stg edit p2 --author "No Mail Address" &&
187 test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
190 test_expect_success 'Set author name' '
191 stg edit p2 --authname "Jane Austen" &&
192 test "$(auth HEAD)" = "Jane Austen, jaustin@example.com"
195 test_expect_success 'Set author email' '
196 stg edit p2 --authemail "jausten@example.com" &&
197 test "$(auth HEAD)" = "Jane Austen, jausten@example.com"
200 test_expect_failure 'Set author date (RFC2822 format)' '
201 stg edit p2 --authdate "Wed, 10 Jul 2013 23:39:00 pm -0300" &&
202 test "$(date HEAD)" = "2013-07-10 23:39:00 -0300"
205 test_expect_failure 'Set author date (ISO 8601 format)' '
206 stg edit p2 --authdate "2013-01-28 22:30:00 -0300" &&
207 test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"
210 test_expect_failure 'Fail to set invalid author date' '
211 command_error stg edit p2 --authdate "28 Jan 1813" &&
212 test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"
215 test_done