diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -862,7 +862,7 @@ def bundle(ui, repo, fname, dest="defaul """ dest = ui.expandpath(dest) other = hg.repository(ui, dest) - o = repo.findoutgoing(other) + o = repo.findoutgoing(other, force=opts['force']) cg = repo.changegroup(o, 'bundle') write_bundle(cg, fname) @@ -1766,7 +1766,7 @@ def incoming(ui, repo, source="default", """ source = ui.expandpath(source) other = hg.repository(ui, source) - incoming = repo.findincoming(other) + incoming = repo.findincoming(other, force=opts["force"]) if not incoming: return @@ -1978,7 +1978,7 @@ def outgoing(ui, repo, dest="default-pus """ dest = ui.expandpath(dest) other = hg.repository(ui, dest) - o = repo.findoutgoing(other) + o = repo.findoutgoing(other, force=opts['force']) o = repo.changelog.nodesbetween(o)[0] if opts['newest_first']: o.reverse() @@ -2066,7 +2066,7 @@ def pull(ui, repo, source="default", **o raise util.Abort(_("pull -r doesn't work for remote repositories yet")) elif opts['rev']: revs = [other.lookup(rev) for rev in opts['rev']] - r = repo.pull(other, heads=revs) + r = repo.pull(other, heads=revs, force=opts['force']) if not r: if opts['update']: return update(ui, repo) @@ -2646,7 +2646,8 @@ table = { _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), "bundle": (bundle, - [], + [('f', 'force', None, + _('run even when remote repository is unrelated'))], _('hg bundle FILE DEST')), "cat": (cat, @@ -2757,6 +2758,8 @@ table = { _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), "incoming|in": (incoming, [('M', 'no-merges', None, _('do not show merges')), + ('f', 'force', None, + _('run even when remote repository is unrelated')), ('', 'style', '', _('display using template map file')), ('n', 'newest-first', None, _('show newest record first')), ('', 'bundle', '', _('file to store the bundles into')), @@ -2791,6 +2794,8 @@ table = { "manifest": (manifest, [], _('hg manifest [REV]')), "outgoing|out": (outgoing, [('M', 'no-merges', None, _('do not show merges')), + ('f', 'force', None, + _('run even when remote repository is unrelated')), ('p', 'patch', None, _('show patch')), ('', 'style', '', _('display using template map file')), ('n', 'newest-first', None, _('show newest record first')), @@ -2808,6 +2813,8 @@ table = { [('u', 'update', None, _('update the working directory to tip after pull')), ('e', 'ssh', '', _('specify ssh command to use')), + ('f', 'force', None, + _('run even when remote repository is unrelated')), ('r', 'rev', [], _('a specific revision you would like to pull')), ('', 'remotecmd', '', _('specify hg command to run on the remote side'))], diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -785,7 +785,7 @@ class localrepository(object): return r - def findincoming(self, remote, base=None, heads=None): + def findincoming(self, remote, base=None, heads=None, force=False): m = self.changelog.nodemap search = [] fetch = {} @@ -898,7 +898,10 @@ class localrepository(object): raise repo.RepoError(_("already have changeset ") + short(f[:4])) if base.keys() == [nullid]: - self.ui.warn(_("warning: pulling from an unrelated repository!\n")) + if force: + self.ui.warn(_("warning: repository is unrelated\n")) + else: + raise util.Abort(_("repository is unrelated")) self.ui.note(_("found new changesets starting at ") + " ".join([short(f) for f in fetch]) + "\n") @@ -907,10 +910,10 @@ class localrepository(object): return fetch.keys() - def findoutgoing(self, remote, base=None, heads=None): + def findoutgoing(self, remote, base=None, heads=None, force=False): if base == None: base = {} - self.findincoming(remote, base, heads) + self.findincoming(remote, base, heads, force=force) self.ui.debug(_("common changesets up to ") + " ".join(map(short, base.keys())) + "\n") @@ -937,7 +940,7 @@ class localrepository(object): # this is the set of all roots we have to push return subset - def pull(self, remote, heads=None): + def pull(self, remote, heads=None, force=False): l = self.lock() # if we have an empty repo, fetch everything @@ -945,7 +948,7 @@ class localrepository(object): self.ui.status(_("requesting all changes\n")) fetch = [nullid] else: - fetch = self.findincoming(remote) + fetch = self.findincoming(remote, force=force) if not fetch: self.ui.status(_("no changes found\n")) @@ -962,7 +965,7 @@ class localrepository(object): base = {} heads = remote.heads() - inc = self.findincoming(remote, base, heads) + inc = self.findincoming(remote, base, heads, force=force) if not force and inc: self.ui.warn(_("abort: unsynced remote changes!\n")) self.ui.status(_("(did you forget to sync? use push -f to force)\n"))