Mercurial > hg > pyhgsh
comparison mercurial/hg.py @ 816:8674b7803714
Warn on pushing unsynced repo or adding new heads
By popular demand
author | mpm@selenic.com |
---|---|
date | Mon, 01 Aug 2005 23:17:22 -0800 |
parents | 0902ffece4b4 |
children | cf1d9a01dd92 |
comparison
equal
deleted
inserted
replaced
815:5a55e3011772 | 816:8674b7803714 |
---|---|
1046 nl.append(n) | 1046 nl.append(n) |
1047 break | 1047 break |
1048 | 1048 |
1049 return nl | 1049 return nl |
1050 | 1050 |
1051 def findincoming(self, remote, base={}): | 1051 def findincoming(self, remote, base=None, heads=None): |
1052 m = self.changelog.nodemap | 1052 m = self.changelog.nodemap |
1053 search = [] | 1053 search = [] |
1054 fetch = [] | 1054 fetch = [] |
1055 seen = {} | 1055 seen = {} |
1056 seenbranch = {} | 1056 seenbranch = {} |
1057 if base == None: | |
1058 base = {} | |
1057 | 1059 |
1058 # assume we're closer to the tip than the root | 1060 # assume we're closer to the tip than the root |
1059 # and start by examining the heads | 1061 # and start by examining the heads |
1060 self.ui.status("searching for changes\n") | 1062 self.ui.status("searching for changes\n") |
1061 heads = remote.heads() | 1063 |
1064 if not heads: | |
1065 heads = remote.heads() | |
1066 | |
1062 unknown = [] | 1067 unknown = [] |
1063 for h in heads: | 1068 for h in heads: |
1064 if h not in m: | 1069 if h not in m: |
1065 unknown.append(h) | 1070 unknown.append(h) |
1066 else: | 1071 else: |
1158 | 1163 |
1159 self.ui.debug("%d total queries\n" % reqcnt) | 1164 self.ui.debug("%d total queries\n" % reqcnt) |
1160 | 1165 |
1161 return fetch | 1166 return fetch |
1162 | 1167 |
1163 def findoutgoing(self, remote): | 1168 def findoutgoing(self, remote, base=None, heads=None): |
1164 base = {} | 1169 if base == None: |
1165 self.findincoming(remote, base) | 1170 base = {} |
1171 self.findincoming(remote, base, heads) | |
1172 | |
1166 remain = dict.fromkeys(self.changelog.nodemap) | 1173 remain = dict.fromkeys(self.changelog.nodemap) |
1167 | 1174 |
1168 # prune everything remote has from the tree | 1175 # prune everything remote has from the tree |
1169 del remain[nullid] | 1176 del remain[nullid] |
1170 remove = base.keys() | 1177 remove = base.keys() |
1200 return 1 | 1207 return 1 |
1201 | 1208 |
1202 cg = remote.changegroup(fetch) | 1209 cg = remote.changegroup(fetch) |
1203 return self.addchangegroup(cg) | 1210 return self.addchangegroup(cg) |
1204 | 1211 |
1205 def push(self, remote): | 1212 def push(self, remote, force=False): |
1206 lock = remote.lock() | 1213 lock = remote.lock() |
1207 update = self.findoutgoing(remote) | 1214 |
1215 base = {} | |
1216 heads = remote.heads() | |
1217 inc = self.findincoming(remote, base, heads) | |
1218 if not force and inc: | |
1219 self.ui.warn("abort: unsynced remote changes!\n") | |
1220 self.ui.status("(did you forget to sync? use push -f to force)\n") | |
1221 return 1 | |
1222 | |
1223 update = self.findoutgoing(remote, base) | |
1208 if not update: | 1224 if not update: |
1209 self.ui.status("no changes found\n") | 1225 self.ui.status("no changes found\n") |
1210 return 1 | 1226 return 1 |
1227 elif not force: | |
1228 if len(heads) < len(self.changelog.heads()): | |
1229 self.ui.warn("abort: push creates new remote branches!\n") | |
1230 self.ui.status("(did you forget to merge?" + | |
1231 " use push -f to force)\n") | |
1232 return 1 | |
1211 | 1233 |
1212 cg = self.changegroup(update) | 1234 cg = self.changegroup(update) |
1213 return remote.addchangegroup(cg) | 1235 return remote.addchangegroup(cg) |
1214 | 1236 |
1215 def changegroup(self, basenodes): | 1237 def changegroup(self, basenodes): |