##// END OF EJS Templates
fetch: rename --force-editor option to --edit, for consistency
Bryan O'Sullivan -
r6225:595a69a0 default
parent child Browse files
Show More
@@ -1,123 +1,125 b''
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
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from mercurial.i18n import _
8 from mercurial.i18n import _
9 from mercurial.node import nullid, short
9 from mercurial.node import nullid, short
10 from mercurial import commands, cmdutil, hg, util
10 from mercurial import commands, cmdutil, hg, util
11
11
12 def fetch(ui, repo, source='default', **opts):
12 def fetch(ui, repo, source='default', **opts):
13 '''Pull changes from a remote repository, merge new changes if needed.
13 '''Pull changes from a remote repository, merge new changes if needed.
14
14
15 This finds all changes from the repository at the specified path
15 This finds all changes from the repository at the specified path
16 or URL and adds them to the local repository.
16 or URL and adds them to the local repository.
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 to include the new changes.
20 working directory is updated to include the new changes.
21
21
22 When a merge occurs, the newly pulled changes are assumed to be
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
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
24 parent, with local changes as the second. To switch the merge
25 order, use --switch-parent.
25 order, use --switch-parent.
26
26
27 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.
28 '''
28 '''
29
29
30 def postincoming(other, modheads):
30 def postincoming(other, modheads):
31 if modheads == 0:
31 if modheads == 0:
32 return 0
32 return 0
33 if modheads == 1:
33 if modheads == 1:
34 return hg.clean(repo, repo.changelog.tip())
34 return hg.clean(repo, repo.changelog.tip())
35 newheads = repo.heads(parent)
35 newheads = repo.heads(parent)
36 newchildren = [n for n in repo.heads(parent) if n != parent]
36 newchildren = [n for n in repo.heads(parent) if n != parent]
37 newparent = parent
37 newparent = parent
38 if newchildren:
38 if newchildren:
39 newparent = newchildren[0]
39 newparent = newchildren[0]
40 hg.clean(repo, newparent)
40 hg.clean(repo, newparent)
41 newheads = [n for n in repo.heads() if n != newparent]
41 newheads = [n for n in repo.heads() if n != newparent]
42 if len(newheads) > 1:
42 if 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
46 return
47 err = False
47 err = False
48 if newheads:
48 if newheads:
49 # By default, we consider the repository we're pulling
49 # By default, we consider the repository we're pulling
50 # *from* as authoritative, so we merge our changes into
50 # *from* as authoritative, so we merge our changes into
51 # theirs.
51 # theirs.
52 if opts['switch_parent']:
52 if opts['switch_parent']:
53 firstparent, secondparent = newparent, newheads[0]
53 firstparent, secondparent = newparent, newheads[0]
54 else:
54 else:
55 firstparent, secondparent = newheads[0], newparent
55 firstparent, secondparent = newheads[0], newparent
56 ui.status(_('updating to %d:%s\n') %
56 ui.status(_('updating to %d:%s\n') %
57 (repo.changelog.rev(firstparent),
57 (repo.changelog.rev(firstparent),
58 short(firstparent)))
58 short(firstparent)))
59 hg.clean(repo, firstparent)
59 hg.clean(repo, firstparent)
60 ui.status(_('merging with %d:%s\n') %
60 ui.status(_('merging with %d:%s\n') %
61 (repo.changelog.rev(secondparent), short(secondparent)))
61 (repo.changelog.rev(secondparent), short(secondparent)))
62 err = hg.merge(repo, secondparent, remind=False)
62 err = hg.merge(repo, secondparent, remind=False)
63 if not err:
63 if not err:
64 mod, add, rem = repo.status()[:3]
64 mod, add, rem = repo.status()[:3]
65 message = (cmdutil.logmessage(opts) or
65 message = (cmdutil.logmessage(opts) or
66 (_('Automated merge with %s') %
66 (_('Automated merge with %s') %
67 util.removeauth(other.url())))
67 util.removeauth(other.url())))
68 force_editor = opts.get('force_editor') or opts.get('edit')
68 n = repo.commit(mod + add + rem, message,
69 n = repo.commit(mod + add + rem, message,
69 opts['user'], opts['date'],
70 opts['user'], opts['date'],
70 force_editor=opts.get('force_editor'))
71 force_editor=force_editor)
71 ui.status(_('new changeset %d:%s merges remote changes '
72 ui.status(_('new changeset %d:%s merges remote changes '
72 'with local\n') % (repo.changelog.rev(n),
73 'with local\n') % (repo.changelog.rev(n),
73 short(n)))
74 short(n)))
74
75
75 def pull():
76 def pull():
76 cmdutil.setremoteconfig(ui, opts)
77 cmdutil.setremoteconfig(ui, opts)
77
78
78 other = hg.repository(ui, ui.expandpath(source))
79 other = hg.repository(ui, ui.expandpath(source))
79 ui.status(_('pulling from %s\n') %
80 ui.status(_('pulling from %s\n') %
80 util.hidepassword(ui.expandpath(source)))
81 util.hidepassword(ui.expandpath(source)))
81 revs = None
82 revs = None
82 if opts['rev']:
83 if opts['rev']:
83 if not other.local():
84 if not other.local():
84 raise util.Abort(_("fetch -r doesn't work for remote "
85 raise util.Abort(_("fetch -r doesn't work for remote "
85 "repositories yet"))
86 "repositories yet"))
86 else:
87 else:
87 revs = [other.lookup(rev) for rev in opts['rev']]
88 revs = [other.lookup(rev) for rev in opts['rev']]
88 modheads = repo.pull(other, heads=revs)
89 modheads = repo.pull(other, heads=revs)
89 return postincoming(other, modheads)
90 return postincoming(other, modheads)
90
91
91 date = opts.get('date')
92 date = opts.get('date')
92 if date:
93 if date:
93 opts['date'] = util.parsedate(date)
94 opts['date'] = util.parsedate(date)
94
95
95 parent, p2 = repo.dirstate.parents()
96 parent, p2 = repo.dirstate.parents()
96 if parent != repo.changelog.tip():
97 if parent != repo.changelog.tip():
97 raise util.Abort(_('working dir not at tip '
98 raise util.Abort(_('working dir not at tip '
98 '(use "hg update" to check out tip)'))
99 '(use "hg update" to check out tip)'))
99 if p2 != nullid:
100 if p2 != nullid:
100 raise util.Abort(_('outstanding uncommitted merge'))
101 raise util.Abort(_('outstanding uncommitted merge'))
101 wlock = lock = None
102 wlock = lock = None
102 try:
103 try:
103 wlock = repo.wlock()
104 wlock = repo.wlock()
104 lock = repo.lock()
105 lock = repo.lock()
105 mod, add, rem = repo.status()[:3]
106 mod, add, rem = repo.status()[:3]
106 if mod or add or rem:
107 if mod or add or rem:
107 raise util.Abort(_('outstanding uncommitted changes'))
108 raise util.Abort(_('outstanding uncommitted changes'))
108 if len(repo.heads()) > 1:
109 if len(repo.heads()) > 1:
109 raise util.Abort(_('multiple heads in this repository '
110 raise util.Abort(_('multiple heads in this repository '
110 '(use "hg heads" and "hg merge" to merge)'))
111 '(use "hg heads" and "hg merge" to merge)'))
111 return pull()
112 return pull()
112 finally:
113 finally:
113 del lock, wlock
114 del lock, wlock
114
115
115 cmdtable = {
116 cmdtable = {
116 'fetch':
117 'fetch':
117 (fetch,
118 (fetch,
118 [('r', 'rev', [], _('a specific revision you would like to pull')),
119 [('r', 'rev', [], _('a specific revision you would like to pull')),
119 ('f', 'force-editor', None, _('edit commit message')),
120 ('e', 'edit', None, _('edit commit message')),
121 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
120 ('', 'switch-parent', None, _('switch parents when merging')),
122 ('', 'switch-parent', None, _('switch parents when merging')),
121 ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
123 ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
122 _('hg fetch [SOURCE]')),
124 _('hg fetch [SOURCE]')),
123 }
125 }
General Comments 0
You need to be logged in to leave comments. Login now