Exemplo n.º 1
0
Arquivo: bundle.py Projeto: LLNL/GRAPE
def unbundlecmd(repo='', branch='', args={}):
    mappings = args["--branchMappings"]
    mapTokens = mappings.split()
    with utility.cd(repo):
        bundleNames = glob.glob("*.bundle")
        for bundleName in bundleNames:
            mappings = ""
            for token in mapTokens:
                sourceDestPair = token.split(":")
                source = sourceDestPair[0]
                dest = sourceDestPair[1]
                bundleHeads = git.bundle("list-heads %s" % bundleName).split("\n")
                bundleBranches = []
                for line in bundleHeads:
                    if "refs/heads" in line:
                        bundleBranches.append(line.split()[1].split("refs/heads/")[1])
                if source.replace('/', '.') in bundleBranches:
                    mappings += "%s:%s " % (source, dest)

            try:
                git.bundle("verify %s" % bundleName)
            except git.GrapeGitError as e:
                print e.gitCommand
                print e.cwd
                print e.gitOutput
                raise e
            git.fetch("--tags -u %s %s" % (bundleName, mappings))
    return True        
Exemplo n.º 2
0
def ensureLocalUpToDateWithRemote(repo='', branch='master'):
    utility.printMsg(
        "Ensuring local branch %s in %s is up to date with origin" %
        (branch, repo))
    with utility.cd(repo):
        # attempt to fetch the requested branch
        try:
            git.fetch("origin", "%s:%s" % (branch, branch))
        except:
            # the branch may not exist, but this is ok
            pass

        if git.currentBranch() == branch:
            return

        if not git.hasBranch(branch):
            # switch to corresponding public branch if the branch does not exist
            public = grapeConfig.workspaceConfig().getPublicBranchFor(branch)
            # figure out if this is a submodule
            relpath = os.path.relpath(repo, utility.workspaceDir())
            relpath = relpath.replace('\\', "/")
            with utility.cd(utility.workspaceDir()):
                # if this is a submodule, get the appropriate public mapping
                if relpath in git.getAllSubmoduleURLMap().keys():
                    public = grapeConfig.workspaceConfig().getMapping(
                        "workspace", "submodulepublicmappings")[public]
            utility.printMsg(
                "Branch %s does not exist in %s, switching to %s and detaching"
                % (branch, repo, public))
            git.checkout(public)
            git.pull("origin %s" % (public))
            git.checkout("--detach HEAD")
Exemplo n.º 3
0
def ensureLocalUpToDateWithRemote(repo = '', branch = 'master'):
    utility.printMsg( "Ensuring local branch %s in %s is up to date with origin" % (branch, repo))
    with utility.cd(repo):
        # attempt to fetch the requested branch
        try:
            git.fetch("origin", "%s:%s" % (branch, branch))
        except:
            # the branch may not exist, but this is ok
            pass
        
        if git.currentBranch() == branch:
            return

        if not git.hasBranch(branch):
            # switch to corresponding public branch if the branch does not exist
            public = grapeConfig.workspaceConfig().getPublicBranchFor(branch)
            # figure out if this is a submodule
            relpath = os.path.relpath(repo, utility.workspaceDir())
            relpath = relpath.replace('\\',"/")
            with utility.cd(utility.workspaceDir()):
                # if this is a submodule, get the appropriate public mapping
                if relpath in git.getAllSubmoduleURLMap().keys():
                    public = grapeConfig.workspaceConfig().getMapping("workspace", "submodulepublicmappings")[public]
            utility.printMsg("Branch %s does not exist in %s, switching to %s and detaching" % (branch, repo, public))
            git.checkout(public)
            git.pull("origin %s" % (public))
            git.checkout("--detach HEAD")
Exemplo n.º 4
0
 def getBranch(self, branch):
     if not branch.startswith("--"):
         try:
             git.shortSHA(branch)
         except:
             if not branch.startswith("origin/"):
                 branch = "origin/" + branch
         # TODO figure out what to do with SHA's in user input
         # TODO always fetch the origin before diffing?
         # TODO figure out ahead behind (git rev-list --left-right --count develop...develop)
         if not self.noFetch and branch.startswith("origin/"):
             git.fetch("origin", branch.partition("/")[2])
     return branch
Exemplo n.º 5
0
 def getBranch(self, branch):
    if not branch.startswith("--"):
       try:
          git.shortSHA(branch)
       except:
          if not branch.startswith("origin/"):
             branch = "origin/"+branch
       # TODO figure out what to do with SHA's in user input
       # TODO always fetch the origin before diffing?
       # TODO figure out ahead behind (git rev-list --left-right --count develop...develop)
       if not self.noFetch and branch.startswith("origin/"):
          git.fetch("origin", branch.partition("/")[2])
    return branch
Exemplo n.º 6
0
    def mergeSubproject(self, args, subproject, subPublic, subprojects, cwd, isSubmodule=True):
        # if we did this merge in a previous run, don't do it again
        try:
            if self.progress["Subproject: %s" % subproject] == "finished":
                return True
        except KeyError:
            pass
        os.chdir(os.path.join(git.baseDir(), subproject))
        mergeArgs = args.copy()
        mergeArgs["--public"] = subPublic

        utility.printMsg("Merging %s into %s for %s %s" % 
                         (subPublic, git.currentBranch(), "submodule" if isSubmodule else "subproject", subproject))
        git.fetch("origin")
        # update our local reference to the remote branch so long as it's fast-forwardable or we don't have it yet..)
        hasRemote = git.hasBranch("origin/%s" % subPublic)
        hasBranch = git.hasBranch(subPublic)
        if  hasRemote and  (git.branchUpToDateWith(subPublic, "origin/%s" % subPublic) or not hasBranch):
            git.fetch("origin %s:%s" % (subPublic, subPublic))
        ret = self.mergeIntoCurrent(subPublic, mergeArgs, subproject)
        conflict = not ret
        if conflict:
            self.progress["stopPoint"] = "Subproject: %s" % subproject
            subprojectKey = "submodules" if isSubmodule else "nested"
            self.progress[subprojectKey] = subprojects
            self.progress["cwd"] = cwd
            conflictedFiles = git.conflictedFiles()
            if conflictedFiles:
                if isSubmodule: 
                    typeStr = "submodule"
                else:
                    typeStr = "nested subproject"
                
                utility.printMsg("Merge in %s %s from %s to %s issued conflicts. Resolve and commit those changes \n"
                                 "using git mergetool and git commit in the submodule, then continue using grape\n"
                                 "%s --continue" % (typeStr, subproject, subPublic, git.currentBranch(), args["<<cmd>>"]))
            else:
                utility.printMsg("Merge in %s failed for an unhandled reason. You may need to stash / commit your current\n"
                                 "changes before doing the merge. Inspect git output above to troubleshoot. Continue using\n"
                                 "grape %s --continue." % (subproject, args["<<cmd>>"]))
            return False
        # if we are resuming from a conflict, the above grape m call would have taken care of continuing.
        # clear out the --continue flag.
        args["--continue"] = False
        # stage the updated submodule
        os.chdir(cwd)
        if isSubmodule:
            git.add(subproject)
        self.progress["Subproject: %s" % subproject] = "finished"
        return True
Exemplo n.º 7
0
def handledCheckout(repo='', branch='master', args=[]):
    checkoutargs = args[0]
    sync = args[1]
    with utility.cd(repo):
        if sync:
            # attempt to fetch the requested branch
            try:
                git.fetch("origin", "%s:%s" % (branch, branch))
            except:
                # the branch may not exist, but ignore the exception
                # and allow the checkout to throw the exception.
                pass
        git.checkout(checkoutargs + ' ' + branch)
        utility.printMsg("Checked out %s in %s" % (branch, repo))

    return True
Exemplo n.º 8
0
def handledCheckout(repo = '', branch = 'master', args = []):
    checkoutargs = args[0]
    sync = args[1]
    with utility.cd(repo):
        if sync:
           # attempt to fetch the requested branch
           try:
               git.fetch("origin", "%s:%s" % (branch, branch))
           except:
               # the branch may not exist, but ignore the exception
               # and allow the checkout to throw the exception.
               pass
        git.checkout(checkoutargs + ' ' + branch)
        utility.printMsg("Checked out %s in %s" % (branch, repo))
        
    return True
Exemplo n.º 9
0
Arquivo: bundle.py Projeto: LLNL/GRAPE
    def execute(self, args):

        tagprefix = args["--tagprefix"]
        branches = args["--branches"]
        
        reponame = args["--name"]
        describePattern = args["--describePattern"]
        
        launchArgs = {}
        
        tagsToBundle = grapeConfig.GrapeConfigParser.parseConfigPairList(args["--bundleTags"])
        recurse = not args["--noRecurse"]
          

        git.fetch()
        git.fetch("--tags")
        branchlist = branches.split()
        
        launchArgs["branchList"] = branchlist
        launchArgs["tags"] = tagsToBundle
        launchArgs["prefix"] = tagprefix
        launchArgs["describePattern"] = describePattern
        launchArgs["--outfile"] = args["--outfile"]
        
        
        otherCommandLauncher = utility.MultiRepoCommandLauncher(bundlecmd, skipSubmodules=True, runInSubmodules=False,
                                                                runInSubprojects=recurse, globalArgs=launchArgs)
    
        otherCommandLauncher.launchFromWorkspaceDir(handleMRE=bundlecmdMRE)

        
        if (recurse):
            launchArgs["branchList"] = args["--submoduleBranches"].split()
            submoduleCommandLauncher = utility.MultiRepoCommandLauncher(bundlecmd,                                                                     
                                                                       runInSubmodules=recurse, 
                                                                       runInSubprojects=False,
                                                                       skipSubmodules=not recurse, 
                                                                       runInOuter=False, 
                                                                       globalArgs=launchArgs
                                                                       )
            
    
            submoduleCommandLauncher.launchFromWorkspaceDir(handleMRE=bundlecmdMRE, noPause=True)

        return True
Exemplo n.º 10
0
def fetchLocal(repo='unknown', branch='master'):
    # branch is actually the list of branches
    branches = branch
    with utility.cd(repo):
        currentBranch = git.currentBranch()

        if len(branches) > 0:
            git.fetch("--prune --tags")
            allRemoteBranches = git.remoteBranches()
            fetchArgs = "origin "
            toFetch = []
            for b in branches:
                if b != currentBranch:
                    if "origin/%s" % b in allRemoteBranches:
                        fetchArgs += "%s:%s " % (b, b)
                        toFetch.append(b)
                else:
                    try:
                        utility.printMsg("Pulling current branch %s in %s" %
                                         (currentBranch, repo))
                        git.pull("origin %s" % currentBranch)
                    except git.GrapeGitError:
                        print(
                            "GRAPE: Could not pull %s from origin. Maybe you haven't pushed it yet?"
                            % currentBranch)
            try:
                if toFetch:
                    utility.printMsg("updating %s in %s" %
                                     (','.join(toFetch), repo))
                    git.fetch(fetchArgs)
            except git.GrapeGitError as e:
                # let non-fast-forward fetches slide
                if "rejected" in e.gitOutput and "non-fast-forward" in e.gitOutput:
                    print e.gitCommand
                    print e.gitOutput
                    print(
                        "GRAPE: WARNING:  one of your public branches %s in %s has local commits! "
                        "Did you forget to create a topic branch?" %
                        (",".join(branches), repo))
                    pass
                elif "Refusing to fetch into current branch" in e.gitOutput:
                    print e.gitOutput
                else:
                    raise e
Exemplo n.º 11
0
Arquivo: status.py Projeto: LLNL/GRAPE
    def checkForLocalPublicBranches(self, args):
        publicBranchesExist = True
        # Check that all public branches exist locally.
        cfg = config.grapeConfig.grapeConfig()
        publicBranches = cfg.getPublicBranchList()
        missingBranches = config.Config.checkIfPublicBranchesExist(
            cfg, utility.workspaceDir(), publicBranches)

        if (len(missingBranches) > 0):
            for mb in missingBranches:
                utility.printMsg(
                    "Repository is missing public branch %s, attempting to fetch it now..."
                    % mb)
                try:
                    git.fetch("origin %s:%s" % (mb, mb))
                    utility.printMsg("%s added as a local branch" % mb)
                except git.GrapeGitError as e:
                    print e.gitOutput
                    publicBranchesExist = False
        return publicBranchesExist
Exemplo n.º 12
0
def fetchLocal(repo='unknown', branch='master'):
    # branch is actually the list of branches
    branches = branch
    with utility.cd(repo):
        currentBranch = git.currentBranch()

        if len(branches) > 0:
            git.fetch("--prune --tags")
            allRemoteBranches = git.remoteBranches()
            fetchArgs = "origin "
            toFetch = []
            for b in branches:
                if b != currentBranch:
                    if "origin/%s" % b in allRemoteBranches:
                        fetchArgs += "%s:%s " % (b, b)
                        toFetch.append(b)
                else:
                    try:
                        utility.printMsg("Pulling current branch %s in %s" % (currentBranch, repo))
                        git.pull("origin %s" % currentBranch)
                    except git.GrapeGitError:
                        print("GRAPE: Could not pull %s from origin. Maybe you haven't pushed it yet?" % currentBranch)                    
            try:
                if toFetch:
                    utility.printMsg("updating %s in %s" % (','.join(toFetch), repo))                         
                    git.fetch(fetchArgs)
            except git.GrapeGitError as e:
                # let non-fast-forward fetches slide
                if "rejected" in e.gitOutput and "non-fast-forward" in e.gitOutput:
                    print e.gitCommand
                    print e.gitOutput
                    print("GRAPE: WARNING:  one of your public branches %s in %s has local commits! "
                          "Did you forget to create a topic branch?" % (",".join(branches), repo))
                    pass
                elif "Refusing to fetch into current branch" in e.gitOutput:
                    print e.gitOutput
                else:
                    raise e
Exemplo n.º 13
0
    def mergeSubproject(self,
                        args,
                        subproject,
                        subPublic,
                        subprojects,
                        cwd,
                        isSubmodule=True):
        # if we did this merge in a previous run, don't do it again
        try:
            if self.progress["Subproject: %s" % subproject] == "finished":
                return True
        except KeyError:
            pass
        os.chdir(os.path.join(git.baseDir(), subproject))
        mergeArgs = args.copy()
        mergeArgs["--public"] = subPublic

        utility.printMsg(
            "Merging %s into %s for %s %s" %
            (subPublic, git.currentBranch(),
             "submodule" if isSubmodule else "subproject", subproject))
        git.fetch("origin")
        # update our local reference to the remote branch so long as it's fast-forwardable or we don't have it yet..)
        hasRemote = git.hasBranch("origin/%s" % subPublic)
        hasBranch = git.hasBranch(subPublic)
        if hasRemote and (git.branchUpToDateWith(
                subPublic, "origin/%s" % subPublic) or not hasBranch):
            git.fetch("origin %s:%s" % (subPublic, subPublic))
        ret = self.mergeIntoCurrent(subPublic, mergeArgs, subproject)
        conflict = not ret
        if conflict:
            self.progress["stopPoint"] = "Subproject: %s" % subproject
            subprojectKey = "submodules" if isSubmodule else "nested"
            self.progress[subprojectKey] = subprojects
            self.progress["cwd"] = cwd
            conflictedFiles = git.conflictedFiles()
            if conflictedFiles:
                if isSubmodule:
                    typeStr = "submodule"
                else:
                    typeStr = "nested subproject"

                utility.printMsg(
                    "Merge in %s %s from %s to %s issued conflicts. Resolve and commit those changes \n"
                    "using git mergetool and git commit in the submodule, then continue using grape\n"
                    "%s --continue" % (typeStr, subproject, subPublic,
                                       git.currentBranch(), args["<<cmd>>"]))
            else:
                utility.printMsg(
                    "Merge in %s failed for an unhandled reason. You may need to stash / commit your current\n"
                    "changes before doing the merge. Inspect git output above to troubleshoot. Continue using\n"
                    "grape %s --continue." % (subproject, args["<<cmd>>"]))
            return False
        # if we are resuming from a conflict, the above grape m call would have taken care of continuing.
        # clear out the --continue flag.
        args["--continue"] = False
        # stage the updated submodule
        os.chdir(cwd)
        if isSubmodule:
            git.add(subproject)
        self.progress["Subproject: %s" % subproject] = "finished"
        return True
Exemplo n.º 14
0
def updateBranchHelper(repo="unknown", branch="master"):
    utility.printMsg("Updating local reference to %s in %s" % (branch, repo))
    return git.fetch("origin %s:%s" % (branch, branch))
Exemplo n.º 15
0
def fetchHelper():
    return git.fetch("origin", warnOnCommError=False, raiseOnCommError=True)