| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test subject preservation with format-patch | am' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | make_patches() { |
| 8 | type=$1 |
| 9 | subject=$2 |
| 10 | test_expect_success "create patches with $type subject" ' |
| 11 | git reset --hard baseline && |
| 12 | echo $type >file && |
| 13 | git commit -a -m "$subject" && |
| 14 | git format-patch -1 --stdout >$type.patch && |
| 15 | git format-patch -1 --stdout -k >$type-k.patch |
| 16 | ' |
| 17 | } |
| 18 | |
| 19 | check_subject() { |
| 20 | git reset --hard baseline && |
| 21 | git am $2 $1.patch && |
| 22 | git log -1 --pretty=format:%B >actual && |
| 23 | test_cmp expect actual |
| 24 | } |
| 25 | |
| 26 | test_expect_success 'setup baseline commit' ' |
| 27 | test_commit baseline file |
| 28 | ' |
| 29 | |
| 30 | SHORT_SUBJECT='short subject' |
| 31 | make_patches short "$SHORT_SUBJECT" |
| 32 | |
| 33 | LONG_SUBJECT1='this is a long subject that is virtually guaranteed' |
| 34 | LONG_SUBJECT2='to require wrapping via format-patch if it is all' |
| 35 | LONG_SUBJECT3='going to appear on a single line' |
| 36 | LONG_SUBJECT="$LONG_SUBJECT1 $LONG_SUBJECT2 $LONG_SUBJECT3" |
| 37 | make_patches long "$LONG_SUBJECT" |
| 38 | |
| 39 | MULTILINE_SUBJECT="$LONG_SUBJECT1 |
| 40 | $LONG_SUBJECT2 |
| 41 | $LONG_SUBJECT3" |
| 42 | make_patches multiline "$MULTILINE_SUBJECT" |
| 43 | |
| 44 | echo "$SHORT_SUBJECT" >expect |
| 45 | test_expect_success 'short subject preserved (format-patch | am)' ' |
| 46 | check_subject short |
| 47 | ' |
| 48 | test_expect_success 'short subject preserved (format-patch -k | am)' ' |
| 49 | check_subject short-k |
| 50 | ' |
| 51 | test_expect_success 'short subject preserved (format-patch -k | am -k)' ' |
| 52 | check_subject short-k -k |
| 53 | ' |
| 54 | |
| 55 | echo "$LONG_SUBJECT" >expect |
| 56 | test_expect_success 'long subject preserved (format-patch | am)' ' |
| 57 | check_subject long |
| 58 | ' |
| 59 | test_expect_success 'long subject preserved (format-patch -k | am)' ' |
| 60 | check_subject long-k |
| 61 | ' |
| 62 | test_expect_success 'long subject preserved (format-patch -k | am -k)' ' |
| 63 | check_subject long-k -k |
| 64 | ' |
| 65 | |
| 66 | echo "$LONG_SUBJECT" >expect |
| 67 | test_expect_success 'multiline subject unwrapped (format-patch | am)' ' |
| 68 | check_subject multiline |
| 69 | ' |
| 70 | test_expect_success 'multiline subject unwrapped (format-patch -k | am)' ' |
| 71 | check_subject multiline-k |
| 72 | ' |
| 73 | echo "$MULTILINE_SUBJECT" >expect |
| 74 | test_expect_success 'multiline subject preserved (format-patch -k | am -k)' ' |
| 75 | check_subject multiline-k -k |
| 76 | ' |
| 77 | |
| 78 | test_done |