##// END OF EJS Templates
fetch: switch the default parent used for a merge...
Bryan O'Sullivan -
r6206:0b6f1249 default
parent child Browse files
Show More
@@ -17,7 +17,12 b" def fetch(ui, repo, source='default', **"
17
17
18 If the pulled changes add a new head, the head is automatically
18 If the pulled changes add a new head, the head is automatically
19 merged, and the result of the merge is committed. Otherwise, the
19 merged, and the result of the merge is committed. Otherwise, the
20 working directory is updated.
20 working directory is updated to include the new changes.
21
22 When a merge occurs, the newly pulled changes are assumed to be
23 "authoritative". The head of the new changes is used as the first
24 parent, with local changes as the second. To switch the merge
25 order, use --switch-parent.
21
26
22 See 'hg help dates' for a list of formats valid for -d/--date.
27 See 'hg help dates' for a list of formats valid for -d/--date.
23 '''
28 '''
@@ -34,15 +39,27 b" def fetch(ui, repo, source='default', **"
34 newparent = newchildren[0]
39 newparent = newchildren[0]
35 hg.clean(repo, newparent)
40 hg.clean(repo, newparent)
36 newheads = [n for n in repo.heads() if n != newparent]
41 newheads = [n for n in repo.heads() if n != newparent]
37 err = False
42 if len(newheads) > 1:
38 if newheads:
39 ui.status(_('merging with new head %d:%s\n') %
40 (repo.changelog.rev(newheads[0]), short(newheads[0])))
41 err = hg.merge(repo, newheads[0], remind=False)
42 if not err and len(newheads) > 1:
43 ui.status(_('not merging with %d other new heads '
43 ui.status(_('not merging with %d other new heads '
44 '(use "hg heads" and "hg merge" to merge them)') %
44 '(use "hg heads" and "hg merge" to merge them)') %
45 (len(newheads) - 1))
45 (len(newheads) - 1))
46 return
47 err = False
48 if newheads:
49 # By default, we consider the repository we're pulling
50 # *from* as authoritative, so we merge our changes into
51 # theirs.
52 if opts['switch_parent']:
53 firstparent, secondparent = newparent, newheads[0]
54 else:
55 firstparent, secondparent = newheads[0], newparent
56 ui.status(_('updating to %d:%s\n') %
57 (repo.changelog.rev(firstparent),
58 short(firstparent)))
59 hg.clean(repo, firstparent)
60 ui.status(_('merging with %d:%s\n') %
61 (repo.changelog.rev(secondparent), short(secondparent)))
62 err = hg.merge(repo, secondparent, remind=False)
46 if not err:
63 if not err:
47 mod, add, rem = repo.status()[:3]
64 mod, add, rem = repo.status()[:3]
48 message = (cmdutil.logmessage(opts) or
65 message = (cmdutil.logmessage(opts) or
@@ -54,6 +71,7 b" def fetch(ui, repo, source='default', **"
54 ui.status(_('new changeset %d:%s merges remote changes '
71 ui.status(_('new changeset %d:%s merges remote changes '
55 'with local\n') % (repo.changelog.rev(n),
72 'with local\n') % (repo.changelog.rev(n),
56 short(n)))
73 short(n)))
74
57 def pull():
75 def pull():
58 cmdutil.setremoteconfig(ui, opts)
76 cmdutil.setremoteconfig(ui, opts)
59
77
@@ -97,6 +115,7 b' cmdtable = {'
97 (fetch,
115 (fetch,
98 [('r', 'rev', [], _('a specific revision you would like to pull')),
116 [('r', 'rev', [], _('a specific revision you would like to pull')),
99 ('f', 'force-editor', None, _('edit commit message')),
117 ('f', 'force-editor', None, _('edit commit message')),
118 ('', 'switch-parent', None, _('switch parents when merging')),
100 ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
119 ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
101 _('hg fetch [SOURCE]')),
120 _('hg fetch [SOURCE]')),
102 }
121 }
@@ -24,6 +24,7 b" hg --cwd c commit -d '3 0' -Amc"
24 hg clone c d
24 hg clone c d
25 hg clone c e
25 hg clone c e
26
26
27 echo % should merge c into a
27 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
28 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
28 ls c
29 ls c
29
30
@@ -37,3 +38,15 b" hg --cwd d tip --template '{desc}\\n'"
37 echo '% fetch over http with auth (should be hidden in desc)'
38 echo '% fetch over http with auth (should be hidden in desc)'
38 hg --cwd e fetch -d '5 0' http://user:password@localhost:$HGPORT/
39 hg --cwd e fetch -d '5 0' http://user:password@localhost:$HGPORT/
39 hg --cwd e tip --template '{desc}\n'
40 hg --cwd e tip --template '{desc}\n'
41
42 hg clone a f
43 hg clone a g
44
45 echo f > f/f
46 hg --cwd f ci -d '6 0' -Amf
47
48 echo g > g/g
49 hg --cwd g ci -d '6 0' -Amg
50
51 echo % should merge f into g
52 hg --cwd g fetch --switch ../f
@@ -15,13 +15,16 b' 1:97d72e5f12c7'
15 adding c
15 adding c
16 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
18 % should merge c into a
18 pulling from ../a
19 pulling from ../a
19 searching for changes
20 searching for changes
20 adding changesets
21 adding changesets
21 adding manifests
22 adding manifests
22 adding file changes
23 adding file changes
23 added 1 changesets with 1 changes to 1 files (+1 heads)
24 added 1 changesets with 1 changes to 1 files (+1 heads)
24 merging with new head 2:97d72e5f12c7
25 updating to 2:97d72e5f12c7
26 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
27 merging with 1:5e056962225c
25 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
26 new changeset 3:cd3a41621cf0 merges remote changes with local
29 new changeset 3:cd3a41621cf0 merges remote changes with local
27 a
30 a
@@ -34,7 +37,9 b' adding changesets'
34 adding manifests
37 adding manifests
35 adding file changes
38 adding file changes
36 added 1 changesets with 1 changes to 1 files (+1 heads)
39 added 1 changesets with 1 changes to 1 files (+1 heads)
37 merging with new head 2:97d72e5f12c7
40 updating to 2:97d72e5f12c7
41 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
42 merging with 1:5e056962225c
38 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
43 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
39 new changeset 3:0b6439e938f9 merges remote changes with local
44 new changeset 3:0b6439e938f9 merges remote changes with local
40 Automated merge with http://localhost:20059/
45 Automated merge with http://localhost:20059/
@@ -45,7 +50,24 b' adding changesets'
45 adding manifests
50 adding manifests
46 adding file changes
51 adding file changes
47 added 1 changesets with 1 changes to 1 files (+1 heads)
52 added 1 changesets with 1 changes to 1 files (+1 heads)
48 merging with new head 2:97d72e5f12c7
53 updating to 2:97d72e5f12c7
54 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
55 merging with 1:5e056962225c
49 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
56 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
50 new changeset 3:0b6439e938f9 merges remote changes with local
57 new changeset 3:0b6439e938f9 merges remote changes with local
51 Automated merge with http://localhost:20059/
58 Automated merge with http://localhost:20059/
59 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
60 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
61 adding f
62 adding g
63 % should merge f into g
64 pulling from ../f
65 searching for changes
66 adding changesets
67 adding manifests
68 adding file changes
69 added 1 changesets with 1 changes to 1 files (+1 heads)
70 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
71 merging with 3:cc6a3744834d
72 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
73 new changeset 4:96d2275e70b4 merges remote changes with local
General Comments 0
You need to be logged in to leave comments. Login now