Commits

kenfred  committed a4d0592

Creating methods for handling recursive push operations

  • Participants
  • Parent commits 20dc0e8

Comments (0)

Files changed (1)

File hgdepends.py

 revFileName     = '.hgdeprev'
 
 
-debugPrints = False
+debugPrints = True
 
 def note(ui, message):
     if debugPrints:
                 # pulling and updating the module repo or it could think
                 # it's its own root repo.
                 # Therefore, we open here to create the file.  We write to it later.
-                open(folderPath + '/' + revFileName, 'w').close()
+                open('%s/%s' % (folderPath, revFileName), 'w').close()
 
                 AppendToRootFile(rootFilePath, newAliasName, dependencySourcePaths[depIndex], depChangeset)
 
                 commands.pull(ui, moduleRepo, source=dependencySourcePaths[depIndex])
                 commands.update(ui, moduleRepo, moduleRepo[depChangeset].node())
 
+                # Add default path to hgrc file so the resulting repo and push
+                with open('%s/.hg/hgrc' % folderPath, 'w') as hgrcFile:
+                    hgrcFile.write('[paths]\ndefault = %s\n' % dependencySourcePaths[depIndex])
+
             try:
                 # Edit the module's reverse dependency file to point back at this repo
                 with open(folderPath + '/' + revFileName, 'a') as revDepFile:
     note(ui, "Committing Dependency Group Repo at %s\n" % repo.root)
     UpdateReverseDependencies(ui, repo, repoClass)
 
+def OutgoingDependencyGroupRepo(ui, repo, repoClass, **kwargs):
+    if kwargs['source'] == 'push':
+        note(ui, "Pushing Dependency Group Repo at %s\n" % repo.root)
+        depFilePath = GetRepoDependencyFilePath(repo)
+        mapFilePath = GetRepoMapDependencyFilePath(repo)
+        if os.path.isfile(depFilePath) and not os.path.isfile(mapFilePath):
+            choice = ui.prompt("The repo has dependencies but no dependency map was found. Push anyway? [Y/n]", default='Y')
+            if choice is not 'Y':
+                note(ui, "Failed to push Dependency Group Repo at %s\n" % repo.root)
+                return 1
+        mapAliases, mapLocations = GetDependencyMap(ui, mapFilePath)
+        for mapIndex, mapLocation in enumerate(mapLocations):
+            depRepo = hg.repository(ui, mapLocation)
+            commands.push(ui, depRepo); 
+
+
 # Every command must take ui and and repo as arguments.
 # opts is a dict where you can find other command line flags.
 #
 #    >>> from mercurial import hg, ui
 #    >>> repo = hg.repository(ui.ui(), path = ".")
 
-
+"""
 def TestCommand(ui, repo, node, **opts):
     # The doc string below will show up in hg help.
-    """Test Command."""
+    ""Test Command.""
     # repo can be indexed based on tags, an sha1, or a revision number.
     ctx = repo[node]
     parents = ctx.parents()
     print("TestCommand")
 
-    """
+    
     try:
         if opts['short']:
             # The string representation of a context returns a smaller portion
     except IndexError:
         # Raise an Abort exception if the node has only one parent.
         raise util.Abort('revision %s has only one parent' % node)
-    """
+"""
 
 # Define hooks -- note that the actual function name it irrelevant.
-def preupdatehook(ui, repo, **kwargs):
-    try:
-        depFilePath = GetRepoDependencyFilePath(repo)
-        mapFilePath = GetRepoMapDependencyFilePath(repo) 
-        
-        # If this is a repo with .hgdep file and it does not yet
-        # have a .hgdepmap file, create it.
-        #if os.path.isfile(depFilePath):
-        #    if not os.path.isfile(mapFilePath):
-        #        open(mapFilePath, 'w').close()
-    except:
-        warn(ui, "Error in Dependency Group Pre-update Hook\n")
-        return 1
-
 def updatehook(ui, repo, **kwargs):
     try:
         repoClass = ClassifyRepo(ui, repo)
         warn(ui, "Error in Dependency Group Pre-Commit Hook\n")
         return 1
 
-
 def commithook(ui, repo, **kwargs):
     try:
         repoClass = ClassifyRepo(ui, repo)
         warn(ui, "Error in Dependency Group Commit Hook\n")
         return
 
+def outgoinghook(ui, repo, **kwargs):
+    print kwargs
+    try:
+        repoClass = ClassifyRepo(ui, repo)
+        if repoClass != 'Regular':
+            OutgoingDependencyGroupRepo(ui, repo, repoClass, **kwargs)
+    except:
+        warn(ui, "Error in Dependency Group Outgoing Hook\n")
+        return
+
 def uisetup(ui):
     # When pre-<cmd> and post-<cmd> hooks are configured by means of
     # the ui.setconfig() function, you must use the ui object passed
     # to uisetup or extsetup.
-    #ui.setconfig("hooks", "pre-update.myextension", preupdatehook)
+    #ui.setconfig("hooks", "pre-update.hgDependencyGroup", preupdatehook)
     ui.setconfig("hooks", "pre-commit.hgDependencyGroup", precommithook)
+    #ui.setconfig("hooks", "preoutgoing.hgDependencyGroup", outgoinghook)
     
 def reposetup(ui, repo):
     # Repository-specific hooks can be configured here. These include the update hook.
     ui.setconfig("hooks", "update.hgDependencyGroup", updatehook)
-    ui.setconfig("hooks", "changegroup.hgDependencyGroup", changegrouphook)    
+    #ui.setconfig("hooks", "changegroup.hgDependencyGroup", changegrouphook)    
     ui.setconfig("hooks", "commit.hgDependencyGroup", commithook)
+    #ui.setconfig("hooks", "outgoing.hgDependencyGroup", outgoinghook)
 
-
+"""
 cmdtable = {
     # cmd name        function call
     'test-command': (TestCommand,
         ('l', 'long', None, 'print long form')],
         '[options] REV')
 }
+"""
 
 testedwith = '2.2.2'