Ejemplo n.º 1
0
Archivo: commit.py Proyecto: LLNL/GRAPE
 def commit(self, commitargs, repo):
     try:
         git.commit(commitargs)
         return True
     except git.GrapeGitError as e: 
         utility.printMsg("Commit in %s failed. Perhaps there were no staged changes? Use -a to commit all modified files." % repo)
         return False
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def continueLocalMerge(self, args):
     status = git.status()
     if "All conflicts fixed but you are still merging." in status:
         git.commit("-m \"GRAPE: merge from %s after conflict resolution.\"" % args["--public"])
         return True
     else:
         return False
Ejemplo n.º 4
0
 def continueLocalMerge(self, args):
     status = git.status()
     if "All conflicts fixed but you are still merging." in status:
         git.commit(
             "-m \"GRAPE: merge from %s after conflict resolution.\"" %
             args["--public"])
         return True
     else:
         return False
Ejemplo n.º 5
0
Archivo: commit.py Proyecto: LLNL/GRAPE
 def commit(self, commitargs, repo):
     try:
         git.commit(commitargs)
         return True
     except git.GrapeGitError as e:
         utility.printMsg(
             "Commit in %s failed. Perhaps there were no staged changes? Use -a to commit all modified files."
             % repo)
         return False
Ejemplo n.º 6
0
 def tickVersion(self, args):
     config = grapeConfig.grapeConfig()
     fileName = config.get("versioning", "file")
     with open(fileName) as f:
         slots = self.readVersion(f, args)
         self.ver = self.slotsToString(args, slots)
         
     if not args["--notick"]:
         slot = args["--slot"]
         if not slot:
             slotMappings = config.getMapping("versioning", "branchSlotMappings")
             if args["--public"]:
                 publicBranch = args["--public"]
             else:
                 publicBranch = config.getPublicBranchFor(git.currentBranch())
             slot = int(slotMappings[publicBranch])
         else:
             slot = int(slot)
         if args["--minor"]:
             slot = 2
         if args["--major"]:
             slot = 1
         # extend the version number if slot comes in too large.
         while len(slots) < slot:
             slots.append(0)
         slots[slot - 1] += 1
         while slot < len(slots):
             slots[slot] = 0
             slot += 1
         # write the new version number to the version file. 
         with open(fileName, 'r+') as f:
             self.ver = self.writeVersion(f, slots, args)
         self.stageVersionFile(fileName)
         if not args["--nocommit"]:
             git.commit("-m \"GRAPE: ticked version to %s\"" % self.ver)
             
     if (not args["--nocommit"]) or args["--tag"]:
         self.tagVersion(self.ver, args)
         if args["--tagNested"]:
             cwd = os.getcwd()
             wsDir = utility.workspaceDir()
             for subproject in grapeConfig.GrapeConfigParser.getAllActiveNestedSubprojectPrefixes():
                 os.chdir(os.path.join(wsDir, subproject))
                 self.tagVersion(self.ver, args)
             os.chdir(cwd)
Ejemplo n.º 7
0
 def initializeVersioning(self, args):
     config = grapeConfig.grapeConfig()
     version = StringIO.StringIO()
     version.write("VERSION_ID = %s" % args["<version>"])
     version.seek(0)
     version = self.readVersion(version, args)
     if args["--file"]:
         fname = args["--file"]
         with open(fname, 'w+') as f:
             version = self.writeVersion(f, version, args)
         self.stageVersionFile(fname)
         config.set("versioning", "file", fname)
         configFile = os.path.join(git.baseDir(), ".grapeconfig")
         grapeConfig.writeConfig(config, configFile)
         self.stageGrapeconfigFile(configFile)
         if not args["--nocommit"]:
             git.commit("%s %s -m \"GRAPE: added initial version info file %s\"" % (fname, configFile, fname))
             self.tagVersion(version, args)
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
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
Ejemplo n.º 10
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