示例#1
0
 def testMergeAbort(self):
     try:
         os.chdir(self.repo)
         git.branch("testMergeAbort/tmp1 HEAD")
         #add a file on the master branch.
         f1name = os.path.join(self.repo, "f1")
         writeFile1(f1name)
         git.add("f1")
         commitStr = "testMergeAbort: added f1"
         git.commit(" -m \"%s\"" % commitStr)
         # also add it on the tmp branch
         git.checkout("testMergeAbort/tmp1")
         writeFile2(f1name)
         git.add("f1")
         git.commit(" -m \"testMergeAbort/tmp1 : added f1\"")
         # a merge should generate a conflict
         git.merge("master -m \"merging from master\"")
         self.assertTrue(False, "conflict did not throw exception")
     except:
         status = git.status()
         self.assertTrue("conflict" in status,
                         "'conflict' not in status message %s " % status)
         git.mergeAbort()
         status = git.status()
         self.assertFalse("conflict" in status,
                          "conflict not removed by aborting merge")
示例#2
0
    def testProjectWideGrapeCommitWithNestedProjects(self):
        try:
            self.assertCanAddNewSubproject(self)
            f1Path = os.path.join(self.subproject, "f1")
            testGrape.writeFile1(f1Path)
            cwd = os.getcwd()
            os.chdir(self.subproject)
            git.add(f1Path)
            # check that git sees the file
            firstStatus = git.status("--porcelain")
            self.assertTrue("f1" in firstStatus)
            os.chdir(cwd)
            grapeMenu.menu().applyMenuChoice("commit", ["-m", "\"adding f1\""])
            # check that running grape commit from the workspace base directory removes f1 from the status
            os.chdir(self.subproject)
            secondStatus = git.status("--porcelain")
            self.assertTrue("f1" not in secondStatus,
                            "commit didn't remove f1 from status")
            os.chdir(cwd)

        except git.GrapeGitError as e:
            self.assertTrue(False,
                            ('\n'.join(self.output) + '\n'.join(self.error) +
                             e.gitCommand).split()[-10:])
            pass
示例#3
0
    def testConflictingSubmoduleMerge(self):
        try:
            self.setUpConflictingSubmoduleMerge()
            subPath = os.path.join(self.repo, "submodule1")
            ret = grapeMenu.menu().applyMenuChoice("m", ["master", "--am"])
            self.assertFalse(
                ret, "grape m did not return False for conflicting merge.")
            # should only have modifications in submodule1, not conflicts
            status = git.status("--porcelain")
            self.assertTrue("UU" not in status and "AA" in status,
                            "unexpected status %s at toplevel" % status)
            os.chdir(subPath)
            status = git.status("--porcelain")
            self.assertTrue("AA" in status,
                            "unexpected status %s in submodule1" % status)

            # resolve the conflict and continue from the submodule's directory
            git.checkout("--ours f1")
            git.add("f1")
            git.commit("-m \"resolved conflict with our f1\"")
            self.setUpConfig()
            ret = grapeMenu.menu().applyMenuChoice("m", ["--continue"])

            # test that we returned successfully
            self.assertTrue(
                ret,
                "grape m --continue did not complete successfully after resolving submodule conflict"
                "\n %s" % self.output.getvalue())

            # test that the submodule master was merged in
            self.assertTrue(
                git.branchUpToDateWith("testSubmoduleMerge2", "master"),
                "grape m --continue did not merge in submodule1`s master branch"
            )

            # test that the outer level master was merged in
            os.chdir(self.repo)
            self.assertTrue(
                git.branchUpToDateWith("testSubmoduleMerge2", "master"),
                "grape m --continue did not merge in the outer level master branch"
            )

            # ensure the gitlink is at the right commit
            git.submodule("update")
            os.chdir(subPath)
            diff = git.diff("testSubmoduleMerge2")
            self.assertFalse(
                diff,
                "checked in gitlink is not at tip of testSubmoduleMerge2")

        except git.GrapeGitError as e:
            self.fail("Uncaught git error executing %s: \n%s" %
                      (e.gitCommand, e.gitOutput))
        except SystemExit:
            self.fail("Uncaught exit\n%s" % self.output.getvalue())
示例#4
0
    def testConflictingNestedSubprojectMerge_MD(self):
        self.setUpConflictingNestedSubprojectMerge()
        os.chdir(self.repo)
        git.checkout(" -b testNestedMerge")

        #make sure we're not up to date with master
        os.chdir(self.subproject)
        self.assertFalse(git.branchUpToDateWith("testNestedMerge", "master"),
                         msg=None)
        os.chdir(self.repo)
        # run grape md --am
        try:
            ret = grapeMenu.menu().applyMenuChoice("md",
                                                   ["--am", "--public=master"],
                                                   globalArgs=["-v"])
        except SystemExit as e:
            self.assertTrue(False, "grape md raised exception %s" % e)
        self.assertFalse(
            ret, "grape md did not return False for conflicting merge.")
        # git status in outer repo should be clean
        status = git.status("--porcelain")
        self.assertFalse(
            status,
            "status is not empty in outer repo after conflict in subproject")
        # git status in subproject should not be clean
        os.chdir(self.subproject)
        status = git.status("--porcelain")
        self.assertIn("AA", status, "no conflicts in subproject status")

        # resolve the conflict
        git.checkout("--ours f1")
        git.add("f1")
        status = git.status("--porcelain")
        self.assertNotIn("AA", status,
                         "conflict not resolved after staging f1")

        # continue the merge
        ret = grapeMenu.menu().applyMenuChoice("md", ["--continue"])
        self.assertTrue(
            ret, "md didn't return successfully after conflict resolution")
        os.chdir(self.subproject)

        self.assertTrue(git.branchUpToDateWith("testNestedMerge", "master"))
        os.chdir(self.repo)
        self.assertTrue(git.branchUpToDateWith("testNestedMerge", "master"))
示例#5
0
    def testConflictingSubmoduleMerge(self):
        try:
            self.setUpConflictingSubmoduleMerge()
            subPath = os.path.join(self.repo, "submodule1")
            ret = grapeMenu.menu().applyMenuChoice("m", ["master", "--am"])
            self.assertFalse(ret, "grape m did not return False for conflicting merge.")
            # should only have modifications in submodule1, not conflicts
            status = git.status("--porcelain")
            self.assertTrue("UU" not in status and "AA" in status, "unexpected status %s at toplevel" % status)
            os.chdir(subPath)
            status = git.status("--porcelain")
            self.assertTrue("AA" in status, "unexpected status %s in submodule1" % status)

            # resolve the conflict and continue from the submodule's directory
            git.checkout("--ours f1")
            git.add("f1")
            git.commit("-m \"resolved conflict with our f1\"")
            self.setUpConfig()
            ret = grapeMenu.menu().applyMenuChoice("m", ["--continue"])

            # test that we returned successfully
            self.assertTrue(ret, "grape m --continue did not complete successfully after resolving submodule conflict"
                                 "\n %s" % self.output.getvalue())

            # test that the submodule master was merged in
            self.assertTrue(git.branchUpToDateWith("testSubmoduleMerge2", "master"),
                            "grape m --continue did not merge in submodule1`s master branch")

            # test that the outer level master was merged in
            os.chdir(self.repo)
            self.assertTrue(git.branchUpToDateWith("testSubmoduleMerge2", "master"),
                            "grape m --continue did not merge in the outer level master branch")

            # ensure the gitlink is at the right commit
            git.submodule("update")
            os.chdir(subPath)
            diff = git.diff("testSubmoduleMerge2")
            self.assertFalse(diff, "checked in gitlink is not at tip of testSubmoduleMerge2")

        except git.GrapeGitError as e:
            self.fail("Uncaught git error executing %s: \n%s" % (e.gitCommand, e.gitOutput))
        except SystemExit:
            self.fail("Uncaught exit\n%s" % self.output.getvalue())
示例#6
0
    def testAdd(self):
        try:
            os.chdir(self.repo)
            f1name = os.path.join(self.repo, "f1")
            writeFile1(f1name)
            git.add("f1")
            statusStr = git.status()
        except git.GrapeGitError as error:
            self.handleGitError(error)

        self.assertTrue("new file:   f1" in statusStr)
示例#7
0
    def testAdd(self):
        try:
            os.chdir(self.repo)
            f1name = os.path.join(self.repo, "f1")
            writeFile1(f1name)
            git.add("f1")
            statusStr = git.status()
        except git.GrapeGitError as error:
            self.handleGitError(error)

        self.assertTrue("new file:   f1" in statusStr)
示例#8
0
    def testProjectWideGrapeCommitWithNestedProjects(self):
        try:
            self.assertCanAddNewSubproject(self)
            f1Path = os.path.join(self.subproject, "f1")
            testGrape.writeFile1(f1Path)
            cwd = os.getcwd()
            os.chdir(self.subproject)
            git.add(f1Path)
            # check that git sees the file
            firstStatus = git.status("--porcelain")
            self.assertTrue("f1" in firstStatus)
            os.chdir(cwd)
            grapeMenu.menu().applyMenuChoice("commit",["-m", "\"adding f1\""])
            # check that running grape commit from the workspace base directory removes f1 from the status
            os.chdir(self.subproject)
            secondStatus = git.status("--porcelain")
            self.assertTrue("f1" not in secondStatus,"commit didn't remove f1 from status")
            os.chdir(cwd)

        except git.GrapeGitError as e:
            self.assertTrue(False, ('\n'.join(self.output)+'\n'.join(self.error) + e.gitCommand).split()[-10:])
            pass
示例#9
0
    def testConflictingNestedSubprojectMerge_MD(self):
        self.setUpConflictingNestedSubprojectMerge()
        os.chdir(self.repo)
        git.checkout(" -b testNestedMerge")
        
        #make sure we're not up to date with master
        os.chdir(self.subproject)
        self.assertFalse(git.branchUpToDateWith("testNestedMerge", "master"), msg=None)
        os.chdir(self.repo)
        # run grape md --am
        try:
            ret = grapeMenu.menu().applyMenuChoice("md", ["--am", "--public=master"], globalArgs=["-v"])
        except SystemExit as e: 
            self.assertTrue(False, "grape md raised exception %s" % e)
        self.assertFalse(ret, "grape md did not return False for conflicting merge.")
        # git status in outer repo should be clean
        status = git.status("--porcelain")
        self.assertFalse(status, "status is not empty in outer repo after conflict in subproject")
        # git status in subproject should not be clean
        os.chdir(self.subproject)
        status = git.status("--porcelain")
        self.assertIn("AA", status, "no conflicts in subproject status")
        
        # resolve the conflict
        git.checkout("--ours f1")
        git.add("f1")
        status = git.status("--porcelain")
        self.assertNotIn("AA", status, "conflict not resolved after staging f1")
        
        # continue the merge
        ret = grapeMenu.menu().applyMenuChoice("md", ["--continue"])
        self.assertTrue(ret, "md didn't return successfully after conflict resolution")
        os.chdir(self.subproject)

        self.assertTrue(git.branchUpToDateWith("testNestedMerge", "master"))
        os.chdir(self.repo)
        self.assertTrue(git.branchUpToDateWith("testNestedMerge", "master"))
示例#10
0
 def testMergeAbort(self):
     try:
         os.chdir(self.repo)
         git.branch("testMergeAbort/tmp1 HEAD")
         #add a file on the master branch.
         f1name = os.path.join(self.repo, "f1")
         writeFile1(f1name)
         git.add("f1")
         commitStr = "testMergeAbort: added f1"
         git.commit(" -m \"%s\"" % commitStr)
         # also add it on the tmp branch
         git.checkout("testMergeAbort/tmp1")
         writeFile2(f1name)
         git.add("f1")
         git.commit(" -m \"testMergeAbort/tmp1 : added f1\"")
         # a merge should generate a conflict
         git.merge("master -m \"merging from master\"")
         self.assertTrue(False,"conflict did not throw exception")
     except:
         status = git.status()
         self.assertTrue("conflict" in status, "'conflict' not in status message %s " % status)
         git.mergeAbort()
         status = git.status()
         self.assertFalse("conflict" in status, "conflict not removed by aborting merge")
示例#11
0
    def testMerge(self):
        # First, test to see if a merge that should work does.
        try:
            os.chdir(self.repo)
            #add a file on the master branch.
            f1name = os.path.join(self.repo, "f1")
            writeFile1(f1name)
            git.add("f1")
            commitStr = "testMerge: added f1"
            git.commit(" -m \"%s\"" % commitStr)
            # edit it on branch testMerge/tmp1
            git.checkout("-b testMerge/tmp1")
            writeFile2(f1name)
            git.commit("-a -m \"edited f1\"")
            # perform same editon master
            git.checkout("master")
            writeFile2(f1name)
            git.commit("-a -m \"edited f1 on master\"")
            # switch back to tmp, merge changes from master down
            git.checkout("testMerge/tmp1")
            output = git.merge(
                "master -m \"merged identical change from master\"")
            log = git.log()
            self.assertTrue("identical change from master" in log)
        except git.GrapeGitError as error:
            self.handleGitError(error)

        # Second, test that a merge that should result in a conflict throws an appropriate GrapeGitError exception.
        try:
            git.checkout("master")
            f2name = os.path.join(self.repo, "f2")
            writeFile3(f2name)
            git.add(f2name)
            git.commit("-m \"added f2\"")
            git.checkout("testMerge/tmp1")
            writeFile2(f2name)
            git.add(f2name)
            git.commit("-m \"added f2 in tmp branch\"")
            git.merge("master -m \"merged master branch into testmerge/tmp1\"")
            self.assertTrue(False,
                            "Merge did not throw grapeGitError for conflict")
        except git.GrapeGitError as error:
            status = git.status()
            self.assertTrue("conflict" in status,
                            "'conflict' not in status message %s" % status)
示例#12
0
    def testMerge(self):
        # First, test to see if a merge that should work does.
        try:
            os.chdir(self.repo)
            #add a file on the master branch.
            f1name = os.path.join(self.repo, "f1")
            writeFile1(f1name)
            git.add("f1")
            commitStr = "testMerge: added f1"
            git.commit(" -m \"%s\"" % commitStr)
            # edit it on branch testMerge/tmp1
            git.checkout("-b testMerge/tmp1")
            writeFile2(f1name)
            git.commit("-a -m \"edited f1\"")
            # perform same editon master
            git.checkout("master")
            writeFile2(f1name)
            git.commit("-a -m \"edited f1 on master\"")
            # switch back to tmp, merge changes from master down
            git.checkout("testMerge/tmp1")
            output = git.merge("master -m \"merged identical change from master\"")
            log = git.log()
            self.assertTrue("identical change from master" in log)
        except git.GrapeGitError as error:
            self.handleGitError(error)

        # Second, test that a merge that should result in a conflict throws an appropriate GrapeGitError exception. 
        try:
            git.checkout("master")
            f2name = os.path.join(self.repo,"f2")
            writeFile3(f2name)
            git.add(f2name)
            git.commit("-m \"added f2\"")
            git.checkout("testMerge/tmp1")
            writeFile2(f2name)
            git.add(f2name)
            git.commit("-m \"added f2 in tmp branch\"")
            git.merge("master -m \"merged master branch into testmerge/tmp1\"")
            self.assertTrue(False,"Merge did not throw grapeGitError for conflict")
        except git.GrapeGitError as error:
            status = git.status()
            self.assertTrue("conflict" in status, "'conflict' not in status message %s" % status)