2 test_description='Test "stg edit"'
6 test_expect_success 'Setup' '
7 printf "000\n111\n222\n" >> 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" &&
17 stg uncommit -n 3 p &&
21 # Commit parse functions.
22 msg () { git cat-file -p $1 | sed '1,/^$/d' | tr '\n' / | sed 's,/*$,,' ; }
23 auth () { git log -n 1 --pretty=format:"%an, %ae" $1 ; }
24 date () { git log -n 1 --pretty=format:%ai $1 ; }
26 test_expect_success 'Edit message of top patch' '
27 test "$(msg HEAD)" = "Second change" &&
28 stg edit p2 -m "Second change 2" &&
29 test "$(msg HEAD)" = "Second change 2"
32 test_expect_success 'Edit message of non-top patch' '
33 test "$(msg HEAD^)" = "First change" &&
34 stg edit p1 -m "First change 2" &&
35 test "$(msg HEAD^)" = "First change 2"
38 test_expect_success 'Edit message of unapplied patch' '
39 test "$(msg $(stg id p3))" = "Third change" &&
40 stg edit p3 -m "Third change 2" &&
41 test "$(msg $(stg id p3))" = "Third change 2"
44 test_expect_success 'Set patch message with --file <file>' '
45 test "$(msg HEAD)" = "Second change 2" &&
46 echo "Pride or Prejudice" > commitmsg &&
47 stg edit p2 -f commitmsg &&
48 test "$(msg HEAD)" = "Pride or Prejudice"
51 test_expect_success 'Set patch message with --file -' '
52 echo "Pride and Prejudice" | stg edit p2 -f - &&
53 test "$(msg HEAD)" = "Pride and Prejudice"
56 ( printf 'From: A U Thor <author@example.com>\nDate: <omitted>'
57 printf '\n\nPride and Prejudice' ) > expected-tmpl
58 omit_date () { sed "s/^Date:.*$/Date: <omitted>/" ; }
60 test_expect_success 'Save template to file' '
61 stg edit --save-template saved-tmpl p2 &&
62 omit_date < saved-tmpl > saved-tmpl-d &&
63 test_cmp expected-tmpl saved-tmpl-d
66 test_expect_success 'Save template to stdout' '
67 stg edit --save-template - p2 > saved-tmpl2 &&
68 omit_date < saved-tmpl2 > saved-tmpl2-d &&
69 test_cmp expected-tmpl saved-tmpl2-d
72 # Test the various ways of invoking the interactive editor. The
73 # preference order should be
76 # 2. stgit.editor (legacy)
86 printf "\n$1\n" >> "\$1"
92 test_expect_failure 'Edit commit message interactively (vi)' '
94 PATH=.:$PATH stg edit p2 &&
95 test "$(msg HEAD)" = "$m/vi"
99 test_expect_success 'Edit commit message interactively (EDITOR)' '
101 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
102 echo $m && echo $(msg HEAD) &&
103 test "$(msg HEAD)" = "$m/e1"
107 test_expect_failure 'Edit commit message interactively (VISUAL)' '
109 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
110 test "$(msg HEAD)" = "$m/e2"
114 test_expect_failure 'Edit commit message interactively (core.editor)' '
116 git config core.editor e3 &&
117 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
118 test "$(msg HEAD)" = "$m/e3"
122 test_expect_success 'Edit commit message interactively (stgit.editor)' '
124 git config stgit.editor e4 &&
125 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
126 test "$(msg HEAD)" = "$m/e4"
130 test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '
132 GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
133 test "$(msg HEAD)" = "$m/e5"
136 rm -f vi e1 e2 e3 e4 e5
137 git config --unset core.editor
138 git config --unset stgit.editor
141 test_expect_failure 'Both noninterative and interactive editing' '
142 EDITOR=./twoliner stg edit -e -m "oneliner" p2 &&
143 test "$(msg HEAD)" = "oneliner/twoliner"
149 sed -i 's/111yy/111YY/' "\$1"
152 test_expect_success 'Edit patch diff' '
153 EDITOR=./diffedit stg edit -d p2 &&
154 test "$(grep 111 foo)" = "111YY"
158 test_expect_success 'Sign a patch' '
160 stg edit --sign p2 &&
161 test "$(msg HEAD)" = "$m//Signed-off-by: C O Mitter <committer@example.com>"
164 test_expect_success 'Acknowledge a patch' '
167 test "$(msg HEAD^)" = "$m//Acked-by: C O Mitter <committer@example.com>"
170 test_expect_success 'Set author' '
171 stg edit p2 --author "Jane Austin <jaustin@example.com>" &&
172 test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
175 test_expect_success 'Fail to set broken author' '
176 command_error stg edit p2 --author "No Mail Address" &&
177 test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
180 test_expect_success 'Set author name' '
181 stg edit p2 --authname "Jane Austen" &&
182 test "$(auth HEAD)" = "Jane Austen, jaustin@example.com"
185 test_expect_success 'Set author email' '
186 stg edit p2 --authemail "jausten@example.com" &&
187 test "$(auth HEAD)" = "Jane Austen, jausten@example.com"
190 test_expect_failure 'Set author date (RFC2822 format)' '
191 stg edit p2 --authdate "Wed, 10 Jul 2013 23:39:00 pm -0300" &&
192 test "$(date HEAD)" = "2013-07-10 23:39:00 -0300"
195 test_expect_failure 'Set author date (ISO 8601 format)' '
196 stg edit p2 --authdate "2013-01-28 22:30:00 -0300" &&
197 test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"
200 test_expect_failure 'Fail to set invalid author date' '
201 command_error stg edit p2 --authdate "28 Jan 1813" &&
202 test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"