# HG changeset patch # User Vadim Gelfer # Date 1142405894 28800 # Node ID d53a18f592be811296997c325131d3e0579f573e # Parent 34d0e2e559ff56b2d74093ec34404f83337b0326 add -f/--force to pull, incoming, outgoing, to work on unrelated repo. before this, push would not push from e.g. "hg" repo to "kernel" repo but other commands worked. this was bad idea, could merge unrelated projects by accident. i did this tonight. now, all commands still work with unrelated repo but need --force/-f. abort is default. this is safer. diff -r 34d0e2e559ff -r d53a18f592be mercurial/commands.py --- a/mercurial/commands.py Tue Mar 14 22:02:41 2006 -0800 +++ b/mercurial/commands.py Tue Mar 14 22:58:14 2006 -0800 @@ -862,7 +862,7 @@ """ 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 @@ """ 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 @@ """ 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 @@ 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 @@ _('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 @@ _('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 @@ "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 @@ [('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 -r 34d0e2e559ff -r d53a18f592be mercurial/localrepo.py --- a/mercurial/localrepo.py Tue Mar 14 22:02:41 2006 -0800 +++ b/mercurial/localrepo.py Tue Mar 14 22:58:14 2006 -0800 @@ -785,7 +785,7 @@ 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 @@ 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 @@ 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 @@ # 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 @@ 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 @@ 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"))