##// END OF EJS Templates
fetch: remove shorthand of --edit colliding against -e/-ssh in remoteopts (BC)...
FUJIWARA Katsunori -
r33013:9c242e9f default
parent child Browse files
Show More
@@ -1,165 +1,165 b''
1 1 # fetch.py - pull and merge remote changes
2 2 #
3 3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 '''pull, update and merge in one command (DEPRECATED)'''
9 9
10 10 from __future__ import absolute_import
11 11
12 12 from mercurial.i18n import _
13 13 from mercurial.node import (
14 14 short,
15 15 )
16 16 from mercurial import (
17 17 cmdutil,
18 18 error,
19 19 exchange,
20 20 hg,
21 21 lock,
22 22 registrar,
23 23 util,
24 24 )
25 25
26 26 release = lock.release
27 27 cmdtable = {}
28 28 command = registrar.command(cmdtable)
29 29 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
30 30 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
31 31 # be specifying the version(s) of Mercurial they are tested with, or
32 32 # leave the attribute unspecified.
33 33 testedwith = 'ships-with-hg-core'
34 34
35 35 @command('fetch',
36 36 [('r', 'rev', [],
37 37 _('a specific revision you would like to pull'), _('REV')),
38 ('e', 'edit', None, _('invoke editor on commit messages')),
38 ('', 'edit', None, _('invoke editor on commit messages')),
39 39 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
40 40 ('', 'switch-parent', None, _('switch parents when merging')),
41 41 ] + cmdutil.commitopts + cmdutil.commitopts2 + cmdutil.remoteopts,
42 42 _('hg fetch [SOURCE]'))
43 43 def fetch(ui, repo, source='default', **opts):
44 44 '''pull changes from a remote repository, merge new changes if needed.
45 45
46 46 This finds all changes from the repository at the specified path
47 47 or URL and adds them to the local repository.
48 48
49 49 If the pulled changes add a new branch head, the head is
50 50 automatically merged, and the result of the merge is committed.
51 51 Otherwise, the working directory is updated to include the new
52 52 changes.
53 53
54 54 When a merge is needed, the working directory is first updated to
55 55 the newly pulled changes. Local changes are then merged into the
56 56 pulled changes. To switch the merge order, use --switch-parent.
57 57
58 58 See :hg:`help dates` for a list of formats valid for -d/--date.
59 59
60 60 Returns 0 on success.
61 61 '''
62 62
63 63 date = opts.get('date')
64 64 if date:
65 65 opts['date'] = util.parsedate(date)
66 66
67 67 parent, _p2 = repo.dirstate.parents()
68 68 branch = repo.dirstate.branch()
69 69 try:
70 70 branchnode = repo.branchtip(branch)
71 71 except error.RepoLookupError:
72 72 branchnode = None
73 73 if parent != branchnode:
74 74 raise error.Abort(_('working directory not at branch tip'),
75 75 hint=_("use 'hg update' to check out branch tip"))
76 76
77 77 wlock = lock = None
78 78 try:
79 79 wlock = repo.wlock()
80 80 lock = repo.lock()
81 81
82 82 cmdutil.bailifchanged(repo)
83 83
84 84 bheads = repo.branchheads(branch)
85 85 bheads = [head for head in bheads if len(repo[head].children()) == 0]
86 86 if len(bheads) > 1:
87 87 raise error.Abort(_('multiple heads in this branch '
88 88 '(use "hg heads ." and "hg merge" to merge)'))
89 89
90 90 other = hg.peer(repo, opts, ui.expandpath(source))
91 91 ui.status(_('pulling from %s\n') %
92 92 util.hidepassword(ui.expandpath(source)))
93 93 revs = None
94 94 if opts['rev']:
95 95 try:
96 96 revs = [other.lookup(rev) for rev in opts['rev']]
97 97 except error.CapabilityError:
98 98 err = _("other repository doesn't support revision lookup, "
99 99 "so a rev cannot be specified.")
100 100 raise error.Abort(err)
101 101
102 102 # Are there any changes at all?
103 103 modheads = exchange.pull(repo, other, heads=revs).cgresult
104 104 if modheads == 0:
105 105 return 0
106 106
107 107 # Is this a simple fast-forward along the current branch?
108 108 newheads = repo.branchheads(branch)
109 109 newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
110 110 if len(newheads) == 1 and len(newchildren):
111 111 if newchildren[0] != parent:
112 112 return hg.update(repo, newchildren[0])
113 113 else:
114 114 return 0
115 115
116 116 # Are there more than one additional branch heads?
117 117 newchildren = [n for n in newchildren if n != parent]
118 118 newparent = parent
119 119 if newchildren:
120 120 newparent = newchildren[0]
121 121 hg.clean(repo, newparent)
122 122 newheads = [n for n in newheads if n != newparent]
123 123 if len(newheads) > 1:
124 124 ui.status(_('not merging with %d other new branch heads '
125 125 '(use "hg heads ." and "hg merge" to merge them)\n') %
126 126 (len(newheads) - 1))
127 127 return 1
128 128
129 129 if not newheads:
130 130 return 0
131 131
132 132 # Otherwise, let's merge.
133 133 err = False
134 134 if newheads:
135 135 # By default, we consider the repository we're pulling
136 136 # *from* as authoritative, so we merge our changes into
137 137 # theirs.
138 138 if opts['switch_parent']:
139 139 firstparent, secondparent = newparent, newheads[0]
140 140 else:
141 141 firstparent, secondparent = newheads[0], newparent
142 142 ui.status(_('updating to %d:%s\n') %
143 143 (repo.changelog.rev(firstparent),
144 144 short(firstparent)))
145 145 hg.clean(repo, firstparent)
146 146 ui.status(_('merging with %d:%s\n') %
147 147 (repo.changelog.rev(secondparent), short(secondparent)))
148 148 err = hg.merge(repo, secondparent, remind=False)
149 149
150 150 if not err:
151 151 # we don't translate commit messages
152 152 message = (cmdutil.logmessage(ui, opts) or
153 153 ('Automated merge with %s' %
154 154 util.removeauth(other.url())))
155 155 editopt = opts.get('edit') or opts.get('force_editor')
156 156 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch')
157 157 n = repo.commit(message, opts['user'], opts['date'], editor=editor)
158 158 ui.status(_('new changeset %d:%s merges remote changes '
159 159 'with local\n') % (repo.changelog.rev(n),
160 160 short(n)))
161 161
162 162 return err
163 163
164 164 finally:
165 165 release(lock, wlock)
General Comments 0
You need to be logged in to leave comments. Login now