1-- Test that typical user errors with 'conflicts' give good error messages.
2
3mtn_setup()
4
5----------
6-- Conflict that is not supported; attribute
7addfile("simple_file", "simple\none\ntwo\nthree\n")
8commit("testbranch", "base")
9base = base_revision()
10
11check(mtn("attr", "set", "simple_file", "foo", "1"), 0, nil, nil)
12commit("testbranch", "left 1")
13left_1 = base_revision()
14
15revert_to(base)
16
17check(mtn("attr", "set", "simple_file", "foo", "2"), 0, nil, nil)
18commit("testbranch", "right 1")
19right_1 = base_revision()
20
21-- invalid number of parameters for 'store'
22check(mtn("conflicts", "store", left_1), 1, nil, true)
23check(mtn("conflicts", "store", left_1, right_1, right_1), 1, nil, true)
24
25-- success
26check(mtn("conflicts", "store", left_1, right_1), 0, nil, true)
27canonicalize("stderr")
28check(samefilestd("conflicts-attr-store-1", "stderr"))
29
30check(mtn("conflicts", "show_remaining", "foo"), 1, nil, true)
31check(qgrep("wrong number of arguments", "stderr"))
32
33check(mtn("conflicts", "show_remaining"), 0, nil, true)
34canonicalize("stderr")
35check(samefilestd("conflicts-attr-show-1", "stderr"))
36
37check(mtn("conflicts", "show_first", "foo"), 1, nil, true)
38check(qgrep("wrong number of arguments", "stderr"))
39
40check(mtn("conflicts", "show_first"), 0, nil, true)
41canonicalize("stderr")
42check(samefilestd("conflicts-attr-show-2", "stderr"))
43
44----------
45-- specify conflicts file not in bookkeeping dir
46check(mtn("conflicts", "--conflicts-file", "conflicts", "store", left_1, right_1), 1, nil, true)
47check(grep("-v", "detected at", "stderr"), 0, true)
48canonicalize("stdout")
49check(samefilestd("conflicts-attr-store-2", "stdout"))
50
51----------
52-- use old conflicts file for new merge
53
54-- get rid of attr conflict, add half of file content conflict
55check(mtn("attr", "set", "simple_file", "foo", "1"), 0, nil, nil)
56writefile("simple_file", "simple\ntwo\nthree\nfour\n")
57commit("testbranch", "right 2")
58right_2 = base_revision()
59
60-- attempt merge with old conflict file
61check(mtn("merge", "--resolve-conflicts"), 1, nil, true)
62check(grep("-v", "detected at", "stderr"), 0, true)
63canonicalize("stdout")
64check(samefilestd("merge-old-conflicts-file", "stdout"))
65
66----------
67-- 'resolve_first' without resolution (issue 202)
68
69-- other half of file content conflict
70revert_to(left_1)
71writefile("simple_file", "simple\none\nthree\nfour\n")
72commit("testbranch", "left 2")
73left_2 = base_revision()
74
75check(mtn("conflicts", "store", left_2, right_2), 0, nil, true)
76
77check(mtn("conflicts", "resolve_first"), 1, nil, true)
78check(qgrep("wrong number of arguments", "stderr"))
79
80----------
81-- specify inconsistent left and right resolutions for duplicate_name
82
83addfile("checkout.sh", "checkout.sh left 1")
84commit("testbranch", "left 3")
85
86revert_to(right_2)
87
88addfile("checkout.sh", "checkout.sh right 1")
89commit("testbranch", "right 3")
90
91check(mtn("conflicts", "store"), 0, nil, true)
92check(samelines("stderr", {"mtn: 2 conflicts with supported resolutions.",
93                           "mtn: stored in '_MTN/conflicts'"}))
94
95-- invalid number of params
96check(mtn("conflicts", "resolve_first_left", "user"), 1, nil, true)
97check(qgrep("wrong number of arguments", "stderr"))
98check(mtn("conflicts", "resolve_first_left", "user", "checkout.sh", "foo"), 1, nil, true)
99check(qgrep("wrong number of arguments", "stderr"))
100check(mtn("conflicts", "resolve_first_right", "user"), 1, nil, true)
101check(qgrep("wrong number of arguments", "stderr"))
102check(mtn("conflicts", "resolve_first_right", "user", "checkout.sh", "foo"), 1, nil, true)
103check(qgrep("wrong number of arguments", "stderr"))
104
105-- both sides specify user file
106check(mtn("conflicts", "resolve_first_left", "user", "checkout.sh"), 0, nil, nil)
107check(mtn("conflicts", "resolve_first_right", "user", "checkout.sh"), 1, nil, true)
108check(grep("-v", "detected at", "stderr"), 0, true)
109canonicalize("stdout")
110check(samelines("stdout",
111{"mtn: misuse: other resolution is content_user; specify 'drop', 'rename', or 'user_rename'"}))
112
113-- not in workspace; report nice error; conflicts file must be under
114-- _MTN, so need workspace. Fixes bug 30473
115check(indir("..", mtn("conflicts", "store", "--db", "resolve_conflicts_errors/test.db", "--branch=testbranch")), 1, nil, true)
116check(grep("workspace required but not found", "stderr"), 0, true)
117check(grep("conflicts file must be under '_MTN'", "stderr"), 0, true)
118
119-- end of file
120