##// END OF EJS Templates
named branches: improve pre-push logic (issue736)...
Sune Foldager -
r8564:6b9ec23b default
parent child Browse files
Show More
@@ -1429,42 +1429,97 b' class localrepository(repo.repository):'
1429 1429 else:
1430 1430 bases, heads = update, self.changelog.heads()
1431 1431
1432 def checkbranch(lheads, rheads, updatelh):
1433 '''
1434 check whether there are more local heads than remote heads on
1435 a specific branch.
1436
1437 lheads: local branch heads
1438 rheads: remote branch heads
1439 updatelh: outgoing local branch heads
1440 '''
1441
1442 warn = 0
1443
1444 if not revs and len(lheads) > len(rheads):
1445 warn = 1
1446 else:
1447 updatelheads = [self.changelog.heads(x, lheads)
1448 for x in updatelh]
1449 newheads = set(sum(updatelheads, [])) & set(lheads)
1450
1451 if not newheads:
1452 return True
1453
1454 for r in rheads:
1455 if r in self.changelog.nodemap:
1456 desc = self.changelog.heads(r, heads)
1457 l = [h for h in heads if h in desc]
1458 if not l:
1459 newheads.add(r)
1460 else:
1461 newheads.add(r)
1462 if len(newheads) > len(rheads):
1463 warn = 1
1464
1465 if warn:
1466 if not rheads: # new branch requires --force
1467 self.ui.warn(_("abort: push creates new"
1468 " remote branch '%s'!\n" %
1469 self[updatelh[0]].branch()))
1470 else:
1471 self.ui.warn(_("abort: push creates new remote heads!\n"))
1472
1473 self.ui.status(_("(did you forget to merge?"
1474 " use push -f to force)\n"))
1475 return False
1476 return True
1477
1432 1478 if not bases:
1433 1479 self.ui.status(_("no changes found\n"))
1434 1480 return None, 1
1435 1481 elif not force:
1436 # check if we're creating new remote heads
1437 # to be a remote head after push, node must be either
1482 # Check for each named branch if we're creating new remote heads.
1483 # To be a remote head after push, node must be either:
1438 1484 # - unknown locally
1439 1485 # - a local outgoing head descended from update
1440 1486 # - a remote head that's known locally and not
1441 1487 # ancestral to an outgoing head
1442
1443 warn = 0
1488 #
1489 # New named branches cannot be created without --force.
1444 1490
1445 if remote_heads == [nullid]:
1446 warn = 0
1447 elif not revs and len(heads) > len(remote_heads):
1448 warn = 1
1491 if remote_heads != [nullid]:
1492 if remote.capable('branchmap'):
1493 localhds = {}
1494 if not revs:
1495 localhds = self.branchmap()
1496 else:
1497 for n in heads:
1498 branch = self[n].branch()
1499 if branch in localhds:
1500 localhds[branch].append(n)
1449 1501 else:
1450 newheads = list(heads)
1451 for r in remote_heads:
1452 if r in self.changelog.nodemap:
1453 desc = self.changelog.heads(r, heads)
1454 l = [h for h in heads if h in desc]
1455 if not l:
1456 newheads.append(r)
1502 localhds[branch] = [n]
1503
1504 remotehds = remote.branchmap()
1505
1506 for lh in localhds:
1507 if lh in remotehds:
1508 rheads = remotehds[lh]
1457 1509 else:
1458 newheads.append(r)
1459 if len(newheads) > len(remote_heads):
1460 warn = 1
1510 rheads = []
1511 lheads = localhds[lh]
1512 updatelh = [upd for upd in update
1513 if self[upd].branch() == lh]
1514 if not updatelh:
1515 continue
1516 if not checkbranch(lheads, rheads, updatelh):
1517 return None, 0
1518 else:
1519 if not checkbranch(heads, remote_heads, update):
1520 return None, 0
1461 1521
1462 if warn:
1463 self.ui.warn(_("abort: push creates new remote heads!\n"))
1464 self.ui.status(_("(did you forget to merge?"
1465 " use push -f to force)\n"))
1466 return None, 0
1467 elif inc:
1522 if inc:
1468 1523 self.ui.warn(_("note: unsynced remote changes!\n"))
1469 1524
1470 1525
@@ -42,6 +42,7 b' pretxnchangegroup.acl = python:hgext.acl'
42 42 pushing to ../b
43 43 searching for changes
44 44 common changesets up to 6675d58eff77
45 invalidating branch cache (tip differs)
45 46 3 changesets found
46 47 list of changesets:
47 48 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -74,6 +75,7 b' sources = push'
74 75 pushing to ../b
75 76 searching for changes
76 77 common changesets up to 6675d58eff77
78 invalidating branch cache (tip differs)
77 79 3 changesets found
78 80 list of changesets:
79 81 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -111,6 +113,7 b' sources = push'
111 113 pushing to ../b
112 114 searching for changes
113 115 common changesets up to 6675d58eff77
116 invalidating branch cache (tip differs)
114 117 3 changesets found
115 118 list of changesets:
116 119 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -408,6 +411,7 b' foo/Bar/** = fred'
408 411 pushing to ../b
409 412 searching for changes
410 413 common changesets up to 6675d58eff77
414 invalidating branch cache (tip differs)
411 415 3 changesets found
412 416 list of changesets:
413 417 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
General Comments 0
You need to be logged in to leave comments. Login now