Raw
1 #!/bin/sh
2
3 test_description='git-am command-line options override saved options'
4
5 . ./test-lib.sh
6
7 format_patch () {
8 git format-patch --stdout -1 "$1" >"$1".eml
9 }
10
11 test_expect_success 'setup' '
12 test_commit initial file &&
13 test_commit first file &&
14
15 git checkout initial &&
16 git mv file file2 &&
17 test_tick &&
18 git commit -m renamed-file &&
19 git tag renamed-file &&
20
21 git checkout -b side initial &&
22 test_commit side1 file &&
23 test_commit side2 file &&
24
25 format_patch side1 &&
26 format_patch side2
27 '
28
29 test_expect_success '--retry fails without in-progress operation' '
30 test_must_fail git am --retry 2>err &&
31 test_grep "operation not in progress" err
32 '
33
34 test_expect_success '--3way overrides --no-3way' '
35 rm -fr .git/rebase-apply &&
36 git reset --hard &&
37 git checkout renamed-file &&
38
39 # Applying side1 will fail as the file has been renamed.
40 test_must_fail git am --no-3way side[12].eml &&
41 test_path_is_dir .git/rebase-apply &&
42 test_cmp_rev renamed-file HEAD &&
43 test -z "$(git ls-files -u)" &&
44
45 # Applying side1 with am --3way will succeed due to the threeway-merge.
46 # Applying side2 will fail as --3way does not apply to it.
47 test_must_fail git am --retry --3way &&
48 test_path_is_dir .git/rebase-apply &&
49 test side1 = "$(cat file2)"
50 '
51
52 test_expect_success '--no-quiet overrides --quiet' '
53 rm -fr .git/rebase-apply &&
54 git reset --hard &&
55 git checkout first &&
56
57 # Applying side1 will be quiet.
58 test_must_fail git am --quiet side[123].eml >out &&
59 test_path_is_dir .git/rebase-apply &&
60 test_grep ! "^Applying: " out &&
61 echo side1 >file &&
62 git add file &&
63
64 # Applying side1 will not be quiet.
65 # Applying side2 will be quiet.
66 git am --no-quiet --continue >out &&
67 echo "Applying: side1" >expected &&
68 test_cmp expected out
69 '
70
71 test_expect_success '--signoff overrides --no-signoff' '
72 rm -fr .git/rebase-apply &&
73 git reset --hard &&
74 git checkout first &&
75
76 test_must_fail git am --no-signoff side[12].eml &&
77 test_path_is_dir .git/rebase-apply &&
78 echo side1 >file &&
79 git add file &&
80 git am --signoff --continue &&
81
82 # Applied side1 will be signed off
83 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
84 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
85 test_cmp expected actual &&
86
87 # Applied side2 will not be signed off
88 test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
89 '
90
91 test_expect_success '--reject overrides --no-reject' '
92 rm -fr .git/rebase-apply &&
93 git reset --hard &&
94 git checkout first &&
95 rm -f file.rej &&
96
97 test_must_fail git am --no-reject side1.eml &&
98 test_path_is_dir .git/rebase-apply &&
99 test_path_is_missing file.rej &&
100
101 test_must_fail git am --retry --reject &&
102 test_path_is_dir .git/rebase-apply &&
103 test_path_is_file file.rej
104 '
105
106 test_done