Show More
@@ -16,7 +16,7 b" def fetch(ui, repo, source='default', **" | |||
|
16 | 16 | This finds all changes from the repository at the specified path |
|
17 | 17 | or URL and adds them to the local repository. |
|
18 | 18 | |
|
19 | If the pulled changes add a new head, the head is automatically | |
|
19 | If the pulled changes add a new branch head, the head is automatically | |
|
20 | 20 | merged, and the result of the merge is committed. Otherwise, the |
|
21 | 21 | working directory is updated to include the new changes. |
|
22 | 22 | |
@@ -33,9 +33,10 b" def fetch(ui, repo, source='default', **" | |||
|
33 | 33 | opts['date'] = util.parsedate(date) |
|
34 | 34 | |
|
35 | 35 | parent, p2 = repo.dirstate.parents() |
|
36 | if parent != repo.changelog.tip(): | |
|
37 | raise util.Abort(_('working dir not at tip ' | |
|
38 | '(use "hg update" to check out tip)')) | |
|
36 | branch = repo[parent].branch() | |
|
37 | if parent != repo[branch].node(): | |
|
38 | raise util.Abort(_('working dir not at branch tip ' | |
|
39 | '(use "hg update" to check out branch tip)')) | |
|
39 | 40 | |
|
40 | 41 | if p2 != nullid: |
|
41 | 42 | raise util.Abort(_('outstanding uncommitted merge')) |
@@ -50,9 +51,9 b" def fetch(ui, repo, source='default', **" | |||
|
50 | 51 | raise util.Abort(_('outstanding uncommitted changes')) |
|
51 | 52 | if del_: |
|
52 | 53 | raise util.Abort(_('working directory is missing some files')) |
|
53 | if len(repo.heads()) > 1: | |
|
54 |
raise util.Abort(_('multiple heads in this |
|
|
55 | '(use "hg heads" and "hg merge" to merge)')) | |
|
54 | if len(repo.branchheads(branch)) > 1: | |
|
55 | raise util.Abort(_('multiple heads in this branch ' | |
|
56 | '(use "hg heads ." and "hg merge" to merge)')) | |
|
56 | 57 | |
|
57 | 58 | cmdutil.setremoteconfig(ui, opts) |
|
58 | 59 | |
@@ -67,27 +68,35 b" def fetch(ui, repo, source='default', **" | |||
|
67 | 68 | else: |
|
68 | 69 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
69 | 70 | |
|
71 | # Are there any changes at all? | |
|
70 | 72 | modheads = repo.pull(other, heads=revs) |
|
71 | 73 | if modheads == 0: |
|
72 | 74 | return 0 |
|
73 | if modheads == 1: | |
|
74 | return hg.clean(repo, repo.changelog.tip()) | |
|
75 | 75 | |
|
76 | newheads = repo.heads(parent) | |
|
77 | newchildren = [n for n in repo.heads(parent) if n != parent] | |
|
76 | # Is this a simple fast-forward along the current branch? | |
|
77 | newheads = repo.branchheads(branch) | |
|
78 | newchildren = repo.changelog.nodesbetween([parent], newheads)[2] | |
|
79 | if len(newheads) == 1: | |
|
80 | if newchildren[0] != parent: | |
|
81 | return hg.clean(repo, newchildren[0]) | |
|
82 | else: | |
|
83 | return | |
|
84 | ||
|
85 | # Are there more than one additional branch heads? | |
|
86 | newchildren = [n for n in newchildren if n != parent] | |
|
78 | 87 | newparent = parent |
|
79 | 88 | if newchildren: |
|
80 | 89 | newparent = newchildren[0] |
|
81 | 90 | hg.clean(repo, newparent) |
|
82 | ||
|
83 | newheads = [n for n in repo.heads() if n != newparent] | |
|
91 | newheads = [n for n in newheads if n != newparent] | |
|
84 | 92 | if len(newheads) > 1: |
|
85 | ui.status(_('not merging with %d other new heads ' | |
|
86 | '(use "hg heads" and "hg merge" to merge them)') % | |
|
93 | ui.status(_('not merging with %d other new branch heads ' | |
|
94 | '(use "hg heads ." and "hg merge" to merge them)\n') % | |
|
87 | 95 | (len(newheads) - 1)) |
|
88 | 96 | return |
|
97 | ||
|
98 | # Otherwise, let's merge. | |
|
89 | 99 | err = False |
|
90 | ||
|
91 | 100 | if newheads: |
|
92 | 101 | # By default, we consider the repository we're pulling |
|
93 | 102 | # *from* as authoritative, so we merge our changes into |
@@ -7,6 +7,7 b' hidehash() { sed "s/changeset 3:........' | |||
|
7 | 7 | echo "[extensions]" >> $HGRCPATH |
|
8 | 8 | echo "fetch=" >> $HGRCPATH |
|
9 | 9 | |
|
10 | echo % test fetch with default branches only | |
|
10 | 11 | hg init a |
|
11 | 12 | echo a > a/a |
|
12 | 13 | hg --cwd a commit -d '1 0' -Ama |
@@ -66,4 +67,93 b' rm i/g' | |||
|
66 | 67 | echo % should abort, because i is modified |
|
67 | 68 | hg --cwd i fetch ../h |
|
68 | 69 | |
|
70 | ||
|
71 | echo % test fetch with named branches | |
|
72 | hg init nbase | |
|
73 | echo base > nbase/a | |
|
74 | hg -R nbase ci -d '1 0' -Am base | |
|
75 | hg -R nbase branch a | |
|
76 | echo a > nbase/a | |
|
77 | hg -R nbase ci -d '2 0' -m a | |
|
78 | hg -R nbase up -C 0 | |
|
79 | hg -R nbase branch b | |
|
80 | echo b > nbase/b | |
|
81 | hg -R nbase ci -Ad '3 0' -m b | |
|
82 | ||
|
83 | echo | |
|
84 | echo % pull in change on foreign branch | |
|
85 | hg clone nbase n1 | |
|
86 | hg clone nbase n2 | |
|
87 | hg -R n1 up -C a | |
|
88 | echo aa > n1/a | |
|
89 | hg -R n1 ci -d '4 0' -m a1 | |
|
90 | ||
|
91 | hg -R n2 up -C b | |
|
92 | hg -R n2 fetch -d '9 0' -m 'merge' n1 | |
|
93 | echo '% parent should be 2 (no automatic update)' | |
|
94 | hg -R n2 parents --template '{rev}\n' | |
|
95 | rm -fr n1 n2 | |
|
96 | ||
|
97 | echo | |
|
98 | echo % pull in changes on both foreign and local branches | |
|
99 | hg clone nbase n1 | |
|
100 | hg clone nbase n2 | |
|
101 | hg -R n1 up -C a | |
|
102 | echo aa > n1/a | |
|
103 | hg -R n1 ci -d '4 0' -m a1 | |
|
104 | hg -R n1 up -C b | |
|
105 | echo bb > n1/b | |
|
106 | hg -R n1 ci -d '5 0' -m b1 | |
|
107 | ||
|
108 | hg -R n2 up -C b | |
|
109 | hg -R n2 fetch -d '9 0' -m 'merge' n1 | |
|
110 | echo '% parent should be 4 (fast forward)' | |
|
111 | hg -R n2 parents --template '{rev}\n' | |
|
112 | rm -fr n1 n2 | |
|
113 | ||
|
114 | echo | |
|
115 | echo '% pull changes on foreign (2 new heads) and local (1 new head) branches' | |
|
116 | echo % with a local change | |
|
117 | hg clone nbase n1 | |
|
118 | hg clone nbase n2 | |
|
119 | hg -R n1 up -C a | |
|
120 | echo a1 > n1/a | |
|
121 | hg -R n1 ci -d '4 0' -m a1 | |
|
122 | hg -R n1 up -C b | |
|
123 | echo bb > n1/b | |
|
124 | hg -R n1 ci -d '5 0' -m b1 | |
|
125 | hg -R n1 up -C 1 | |
|
126 | echo a2 > n1/a | |
|
127 | hg -R n1 ci -d '6 0' -m a2 | |
|
128 | ||
|
129 | hg -R n2 up -C b | |
|
130 | echo change >> n2/c | |
|
131 | hg -R n2 ci -Ad '7 0' -m local | |
|
132 | hg -R n2 fetch -d '9 0' -m 'merge' n1 | |
|
133 | echo '% parent should be 7 (new merge changeset)' | |
|
134 | hg -R n2 parents --template '{rev}\n' | |
|
135 | rm -fr n1 n2 | |
|
136 | ||
|
137 | echo '% pull in changes on foreign (merge of local branch) and local (2 new' | |
|
138 | echo '% heads) with a local change' | |
|
139 | hg clone nbase n1 | |
|
140 | hg clone nbase n2 | |
|
141 | hg -R n1 up -C a | |
|
142 | hg -R n1 merge b | |
|
143 | hg -R n1 ci -d '4 0' -m merge | |
|
144 | hg -R n1 up -C 2 | |
|
145 | echo c > n1/a | |
|
146 | hg -R n1 ci -d '5 0' -m c | |
|
147 | hg -R n1 up -C 2 | |
|
148 | echo cc > n1/a | |
|
149 | hg -R n1 ci -d '6 0' -m cc | |
|
150 | ||
|
151 | hg -R n2 up -C b | |
|
152 | echo change >> n2/b | |
|
153 | hg -R n2 ci -Ad '7 0' -m local | |
|
154 | hg -R n2 fetch -d '9 0' -m 'merge' n1 | |
|
155 | echo '% parent should be 3 (fetch did not merge anything)' | |
|
156 | hg -R n2 parents --template '{rev}\n' | |
|
157 | rm -fr n1 n2 | |
|
158 | ||
|
69 | 159 | true |
@@ -1,3 +1,4 b'' | |||
|
1 | % test fetch with default branches only | |
|
1 | 2 | adding a |
|
2 | 3 | updating working directory |
|
3 | 4 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
@@ -79,3 +80,93 b' 1 files updated, 0 files merged, 0 files' | |||
|
79 | 80 | new changeset 4:55aa4f32ec59 merges remote changes with local |
|
80 | 81 | % should abort, because i is modified |
|
81 | 82 | abort: working directory is missing some files |
|
83 | % test fetch with named branches | |
|
84 | adding a | |
|
85 | marked working directory as branch a | |
|
86 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
87 | marked working directory as branch b | |
|
88 | adding b | |
|
89 | created new head | |
|
90 | ||
|
91 | % pull in change on foreign branch | |
|
92 | updating working directory | |
|
93 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
94 | updating working directory | |
|
95 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
96 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
97 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
98 | pulling from n1 | |
|
99 | searching for changes | |
|
100 | adding changesets | |
|
101 | adding manifests | |
|
102 | adding file changes | |
|
103 | added 1 changesets with 1 changes to 1 files | |
|
104 | % parent should be 2 (no automatic update) | |
|
105 | 2 | |
|
106 | ||
|
107 | % pull in changes on both foreign and local branches | |
|
108 | updating working directory | |
|
109 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
110 | updating working directory | |
|
111 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
112 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
113 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
114 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
115 | pulling from n1 | |
|
116 | searching for changes | |
|
117 | adding changesets | |
|
118 | adding manifests | |
|
119 | adding file changes | |
|
120 | added 2 changesets with 2 changes to 2 files | |
|
121 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
122 | % parent should be 4 (fast forward) | |
|
123 | 4 | |
|
124 | ||
|
125 | % pull changes on foreign (2 new heads) and local (1 new head) branches | |
|
126 | % with a local change | |
|
127 | updating working directory | |
|
128 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
129 | updating working directory | |
|
130 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
131 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
132 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
133 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
|
134 | created new head | |
|
135 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
136 | adding c | |
|
137 | pulling from n1 | |
|
138 | searching for changes | |
|
139 | adding changesets | |
|
140 | adding manifests | |
|
141 | adding file changes | |
|
142 | added 3 changesets with 3 changes to 2 files (+2 heads) | |
|
143 | updating to 5:708c6cce3d26 | |
|
144 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
|
145 | merging with 3:d83427717b1f | |
|
146 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
147 | new changeset 7:48f1a33f52af merges remote changes with local | |
|
148 | % parent should be 7 (new merge changeset) | |
|
149 | 7 | |
|
150 | % pull in changes on foreign (merge of local branch) and local (2 new | |
|
151 | % heads) with a local change | |
|
152 | updating working directory | |
|
153 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
154 | updating working directory | |
|
155 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
156 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
157 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
158 | (branch merge, don't forget to commit) | |
|
159 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
160 | created new head | |
|
161 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
162 | created new head | |
|
163 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
164 | pulling from n1 | |
|
165 | searching for changes | |
|
166 | adding changesets | |
|
167 | adding manifests | |
|
168 | adding file changes | |
|
169 | added 3 changesets with 2 changes to 1 files (+2 heads) | |
|
170 | not merging with 1 other new branch heads (use "hg heads ." and "hg merge" to merge them) | |
|
171 | % parent should be 3 (fetch did not merge anything) | |
|
172 | 3 |
General Comments 0
You need to be logged in to leave comments.
Login now