예제 #1
0
파일: commit.py 프로젝트: LLNL/GRAPE
    def execute(self, args):
        commitargs = ""
        if args['-a']: 
            commitargs = commitargs +  " -a"
        elif args["<filetree>"]:
            commitargs = commitargs + " %s"% args["<filetree>"]
        if not args['-m']:
            args["-m"] = utility.userInput("Please enter commit message:")
        commitargs += " -m \"%s\"" % args["-m"]
         
        wsDir = utility.workspaceDir()
        os.chdir(wsDir)

        submodules = [(True, x ) for x in git.getModifiedSubmodules()]
        subprojects = [(False, x) for x in grapeConfig.GrapeConfigParser.getAllActiveNestedSubprojectPrefixes()]
        for stage,sub in submodules +  subprojects:
            os.chdir(os.path.join(wsDir,sub))
            subStatus = git.status("--porcelain -uno")
            if subStatus:
                utility.printMsg("Committing in %s..." % sub)
                if self.commit(commitargs, sub) and stage: 
                    os.chdir(wsDir)
                    utility.printMsg("Staging committed change in %s..." % sub)
                    git.add(sub)
        
        os.chdir(wsDir)
        if submodules or git.status("--porcelain"): 
            utility.printMsg("Performing commit in outer level project...")
            self.commit(commitargs, wsDir)
        return True
예제 #2
0
파일: commit.py 프로젝트: LLNL/GRAPE
    def execute(self, args):
        commitargs = ""
        if args['-a']:
            commitargs = commitargs + " -a"
        elif args["<filetree>"]:
            commitargs = commitargs + " %s" % args["<filetree>"]
        if not args['-m']:
            args["-m"] = utility.userInput("Please enter commit message:")
        commitargs += " -m \"%s\"" % args["-m"]

        wsDir = utility.workspaceDir()
        os.chdir(wsDir)

        submodules = [(True, x) for x in git.getModifiedSubmodules()]
        subprojects = [(False, x) for x in grapeConfig.GrapeConfigParser.
                       getAllActiveNestedSubprojectPrefixes()]
        for stage, sub in submodules + subprojects:
            os.chdir(os.path.join(wsDir, sub))
            subStatus = git.status("--porcelain -uno")
            if subStatus:
                utility.printMsg("Committing in %s..." % sub)
                if self.commit(commitargs, sub) and stage:
                    os.chdir(wsDir)
                    utility.printMsg("Staging committed change in %s..." % sub)
                    git.add(sub)

        os.chdir(wsDir)
        if submodules or git.status("--porcelain"):
            utility.printMsg("Performing commit in outer level project...")
            self.commit(commitargs, wsDir)
        return True
예제 #3
0
파일: mergeDevelop.py 프로젝트: LLNL/GRAPE
 def merge(self, branch, strategy, args):
     squashArg = "--squash" if args["--squash"] else ""
     try:
         git.merge("%s %s %s" % (squashArg, branch, strategy))
         return True
     except git.GrapeGitError as error:
         print error.gitOutput
         if "conflict" in error.gitOutput.lower():
             if args['--at'] or args['--ay']:
                 if args['--at']:
                     utility.printMsg("Resolving conflicted files by accepting changes from %s." % branch)
                     checkoutArg = "--theirs"
                 else:
                     utility.printMsg("Resolving conflicted files by accepting changes from your branch.")
                     checkoutArg = "--ours"
                 try:
                     path = git.baseDir()
                     git.checkout("%s %s" % (checkoutArg, path))
                     git.add("%s" % path)
                     git.commit("-m 'Resolve conflicts using %s'" % checkoutArg)
                     return True
                 except git.GrapeGitError as resolveError:
                     print resolveError.gitOutput
                     return False
             else:
                 utility.printMsg("Conflicts generated. Resolve using git mergetool, then continue "
                                  "with grape %s --continue. " % args["<<cmd>>"])
                 return False
         else:
             print("Merge command %s failed. Quitting." % error.gitCommand)
             return False
예제 #4
0
파일: mergeDevelop.py 프로젝트: LLNL/GRAPE
    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
예제 #5
0
파일: mergeDevelop.py 프로젝트: LLNL/GRAPE
 def merge(self, branch, strategy, args):
     squashArg = "--squash" if args["--squash"] else ""
     try:
         git.merge("%s %s %s" % (squashArg, branch, strategy))
         return True
     except git.GrapeGitError as error:
         print error.gitOutput
         if "conflict" in error.gitOutput.lower():
             if args['--at'] or args['--ay']:
                 if args['--at']:
                     utility.printMsg(
                         "Resolving conflicted files by accepting changes from %s."
                         % branch)
                     checkoutArg = "--theirs"
                 else:
                     utility.printMsg(
                         "Resolving conflicted files by accepting changes from your branch."
                     )
                     checkoutArg = "--ours"
                 try:
                     path = git.baseDir()
                     git.checkout("%s %s" % (checkoutArg, path))
                     git.add("%s" % path)
                     git.commit("-m 'Resolve conflicts using %s'" %
                                checkoutArg)
                     return True
                 except git.GrapeGitError as resolveError:
                     print resolveError.gitOutput
                     return False
             else:
                 utility.printMsg(
                     "Conflicts generated. Resolve using git mergetool, then continue "
                     "with grape %s --continue. " % args["<<cmd>>"])
                 return False
         else:
             print("Merge command %s failed. Quitting." % error.gitCommand)
             return False
예제 #6
0
파일: mergeDevelop.py 프로젝트: LLNL/GRAPE
    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
예제 #7
0
    def execute(self, args):
        name = args["--name"]
        prefix = args["--prefix"]
        url = args["--url"]
        fullurl = utility.parseSubprojectRemoteURL(url)
        branch = args["--branch"]
        config = grapeConfig.grapeConfig()
        projectType = self.parseSubprojectType(config, args)
        proceed = args["--noverify"]
        if projectType == "subtree":
            #  whether or not to squash
            squash = args["--squash"] or config.get(
                "subtrees", "mergePolicy").strip().lower() == "squash"
            squash = squash and not args["--nosquash"]
            squash_arg = "--squash" if squash else ""
            # expand the URL
            if not proceed:
                proceed = utility.userInput(
                    "About to create a subtree called %s at path %s,\n"
                    "cloned from %s at %s " % (name, prefix, fullurl, branch) +
                    ("using a squash merge." if squash else "") +
                    "\nProceed? [y/n]", "y")

            if proceed:
                os.chdir(utility.workspaceDir())
                git.subtree("add %s --prefix=%s %s %s" %
                            (squash_arg, prefix, fullurl, branch))

                #update the configuration file
                current_cfg_names = config.get("subtrees", "names").split()
                if not current_cfg_names or current_cfg_names[0].lower(
                ) == "none":
                    config.set("subtrees", "names", name)
                else:
                    current_cfg_names.append(name)
                    config.set("subtrees", "names",
                               ' '.join(current_cfg_names))

                section = "subtree-%s" % name
                config.add_section(section)
                config.set(section, "prefix", prefix)
                config.set(section, "remote", url)
                config.set(section, "topicPrefixMappings", "?:%s" % branch)
                with open(os.path.join(utility.workspaceDir(), ".grapeconfig"),
                          "w") as f:
                    config.write(f)
                utility.printMsg(
                    "Successfully added subtree branch. \n"
                    "Updated .grapeconfig file. Review changes and then commit. "
                )
        elif projectType == "submodule":
            if not proceed:
                proceed = utility.userInput(
                    "about to add %s as a submodule at path %s,\n"
                    "cloned from %s at branch %s.\nproceed? [y/n]" %
                    (name, prefix, url, branch), "y")
            if proceed:
                git.submodule("add --name %s --branch %s %s %s" %
                              (name, branch, url, prefix))
                print(
                    "Successfully added submodule %s at %s. Please review changes and commit."
                    % (name, prefix))
        elif projectType == "nested":
            if not proceed:
                proceed = utility.userInput(
                    " about to clone %s as a nested git repo at path %s,\n"
                    "cloned from %s at branch %s.\nProceed? [y/n]" %
                    (name, prefix, url, branch), 'y')
            if proceed:
                git.clone("%s %s" % (fullurl, prefix))
                ignorePath = os.path.join(git.baseDir(), ".gitignore")
                with open(ignorePath, 'a') as ignore:
                    ignore.writelines([prefix + '\n'])
                git.add(ignorePath)
                wsConfig = grapeConfig.workspaceConfig()
                currentSubprojects = wsConfig.getList("nestedProjects",
                                                      "names")
                currentSubprojects.append(name)
                wsConfig.set("nestedProjects", "names",
                             ' '.join(currentSubprojects))
                newSection = "nested-%s" % name
                wsConfig.ensureSection(newSection)
                wsConfig.set(newSection, "prefix", prefix)
                wsConfig.set(newSection, "url", url)
                configFileName = os.path.join(utility.workspaceDir(),
                                              ".grapeconfig")
                with open(os.path.join(configFileName), 'w') as f:
                    wsConfig.write(f)
                git.add(configFileName)
                git.commit("%s %s -m \"GRAPE: Added nested subproject %s\"" %
                           (ignorePath, configFileName, prefix))
                # update the runtime config with the new workspace .grapeconfig's settings.
                grapeConfig.read()

                userConfig = grapeConfig.grapeUserConfig()
                userConfig.ensureSection(newSection)
                userConfig.set(newSection, "active", "True")
                grapeConfig.writeConfig(
                    userConfig,
                    os.path.join(utility.workspaceDir(), ".git",
                                 ".grapeuserconfig"))

        return True
예제 #8
0
파일: addSubproject.py 프로젝트: LLNL/GRAPE
    def execute(self, args):
        name = args["--name"]
        prefix = args["--prefix"]
        url = args["--url"]
        fullurl = utility.parseSubprojectRemoteURL(url)
        branch = args["--branch"]
        config = grapeConfig.grapeConfig()
        projectType = self.parseSubprojectType(config, args)
        proceed = args["--noverify"]
        if projectType == "subtree":
            #  whether or not to squash
            squash = args["--squash"] or config.get("subtrees", "mergePolicy").strip().lower() == "squash"
            squash = squash and not args["--nosquash"]
            squash_arg = "--squash" if squash else ""
            # expand the URL
            if not proceed:
                proceed = utility.userInput("About to create a subtree called %s at path %s,\n"
                                            "cloned from %s at %s " % (name, prefix, fullurl, branch) +
                                            ("using a squash merge." if squash else "") + "\nProceed? [y/n]", "y")

            if proceed:
                os.chdir(utility.workspaceDir())
                git.subtree("add %s --prefix=%s %s %s" % (squash_arg, prefix, fullurl, branch))

                #update the configuration file
                current_cfg_names = config.get("subtrees", "names").split()
                if not current_cfg_names or current_cfg_names[0].lower() == "none":
                    config.set("subtrees", "names", name)
                else:
                    current_cfg_names.append(name)
                    config.set("subtrees", "names", ' '.join(current_cfg_names))

                section = "subtree-%s" % name
                config.add_section(section)
                config.set(section, "prefix", prefix)
                config.set(section, "remote", url)
                config.set(section, "topicPrefixMappings", "?:%s" % branch)
                with open(os.path.join(utility.workspaceDir(), ".grapeconfig"), "w") as f:
                    config.write(f)
                utility.printMsg("Successfully added subtree branch. \n"
                      "Updated .grapeconfig file. Review changes and then commit. ")
        elif projectType == "submodule":
            if not proceed:
                proceed = utility.userInput("about to add %s as a submodule at path %s,\n"
                                            "cloned from %s at branch %s.\nproceed? [y/n]" %
                                            (name, prefix, url, branch), "y")
            if proceed:
                git.submodule("add --name %s --branch %s %s %s" % (name, branch, url, prefix))
                print("Successfully added submodule %s at %s. Please review changes and commit." % (name, prefix))
        elif projectType == "nested":
            if not proceed:
                proceed = utility.userInput(" about to clone %s as a nested git repo at path %s,\n"
                                            "cloned from %s at branch %s.\nProceed? [y/n]" %
                                            (name, prefix, url, branch), 'y')
            if proceed:
                git.clone("%s %s" % (fullurl, prefix))
                ignorePath = os.path.join(git.baseDir(), ".gitignore")
                with open(ignorePath, 'a') as ignore:
                    ignore.writelines([prefix+'\n'])
                git.add(ignorePath)
                wsConfig = grapeConfig.workspaceConfig()
                currentSubprojects = wsConfig.getList("nestedProjects", "names")
                currentSubprojects.append(name)
                wsConfig.set("nestedProjects", "names", ' '.join(currentSubprojects))
                newSection = "nested-%s" % name
                wsConfig.ensureSection(newSection)
                wsConfig.set(newSection, "prefix", prefix)
                wsConfig.set(newSection, "url", url)
                configFileName = os.path.join(utility.workspaceDir(), ".grapeconfig")
                with open(os.path.join(configFileName), 'w') as f:
                    wsConfig.write(f)
                git.add(configFileName)
                git.commit("%s %s -m \"GRAPE: Added nested subproject %s\"" % (ignorePath, configFileName, prefix))
                # update the runtime config with the new workspace .grapeconfig's settings.
                grapeConfig.read()

                userConfig = grapeConfig.grapeUserConfig()
                userConfig.ensureSection(newSection)
                userConfig.set(newSection, "active", "True")
                grapeConfig.writeConfig(userConfig, os.path.join(utility.workspaceDir(), ".git", ".grapeuserconfig"))

        return True
예제 #9
0
파일: version.py 프로젝트: LLNL/GRAPE
    def stageGrapeconfigFile(fname):
        git.add(fname)

        return True
예제 #10
0
파일: version.py 프로젝트: LLNL/GRAPE
 def stageVersionFile(fname):
     print ( "STAGING %s" % fname)
     git.add(fname)
     return True