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