# HG changeset patch # User mpm@selenic.com # Date 1122967042 28800 # Node ID 8674b7803714f2835c7908ae7a13b514865c2c00 # Parent 5a55e3011772f8b593cd666e3291e45f646a8656 Warn on pushing unsynced repo or adding new heads By popular demand diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -1048,17 +1048,22 @@ class localrepository: return nl - def findincoming(self, remote, base={}): + def findincoming(self, remote, base=None, heads=None): m = self.changelog.nodemap search = [] fetch = [] seen = {} seenbranch = {} + if base == None: + base = {} # assume we're closer to the tip than the root # and start by examining the heads self.ui.status("searching for changes\n") - heads = remote.heads() + + if not heads: + heads = remote.heads() + unknown = [] for h in heads: if h not in m: @@ -1160,9 +1165,11 @@ class localrepository: return fetch - def findoutgoing(self, remote): - base = {} - self.findincoming(remote, base) + def findoutgoing(self, remote, base=None, heads=None): + if base == None: + base = {} + self.findincoming(remote, base, heads) + remain = dict.fromkeys(self.changelog.nodemap) # prune everything remote has from the tree @@ -1202,12 +1209,27 @@ class localrepository: cg = remote.changegroup(fetch) return self.addchangegroup(cg) - def push(self, remote): + def push(self, remote, force=False): lock = remote.lock() - update = self.findoutgoing(remote) + + base = {} + heads = remote.heads() + inc = self.findincoming(remote, base, heads) + 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") + return 1 + + update = self.findoutgoing(remote, base) if not update: self.ui.status("no changes found\n") return 1 + elif not force: + if len(heads) < len(self.changelog.heads()): + self.ui.warn("abort: push creates new remote branches!\n") + self.ui.status("(did you forget to merge?" + + " use push -f to force)\n") + return 1 cg = self.changegroup(update) return remote.addchangegroup(cg) diff --git a/tests/test-push-warn b/tests/test-push-warn new file mode 100755 --- /dev/null +++ b/tests/test-push-warn @@ -0,0 +1,28 @@ +#!/bin/sh + +mkdir a +cd a +hg init +echo foo > t1 +hg add t1 +hg commit -m "1" -d "0 0" + +cd .. +hg clone a b + +cd a +echo foo > t2 +hg add t2 +hg commit -m "2" -d "0 0" + +cd ../b +echo foo > t3 +hg add t3 +hg commit -m "3" -d "0 0" + +hg push ../a +hg pull ../a +hg push ../a +hg up -m +hg commit -m "4" -d "0 0" +hg push ../a diff --git a/tests/test-push-warn.out b/tests/test-push-warn.out new file mode 100644 --- /dev/null +++ b/tests/test-push-warn.out @@ -0,0 +1,35 @@ ++ hg init ++ hg add t1 ++ hg commit -m 1 -d 0 0 ++ hg clone a b ++ hg add t2 ++ hg commit -m 2 -d 0 0 ++ hg add t3 ++ hg commit -m 3 -d 0 0 ++ hg push ../a +pushing to ../a +searching for changes +abort: unsynced remote changes! +(did you forget to sync? use push -f to force) ++ hg pull ../a +pulling from ../a +searching for changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +(run 'hg update' to get a working copy) ++ hg push ../a +pushing to ../a +searching for changes +abort: push creates new remote branches! +(did you forget to merge? use push -f to force) ++ hg up -m ++ hg commit -m 4 -d 0 0 ++ hg push ../a +pushing to ../a +searching for changes +adding changesets +adding manifests +adding file changes +added 2 changesets with 2 changes to 2 files