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
def testConflictingMerge_MD(self): self.setUpConflictingMerge() try: self.assertNotEqual(git.shortSHA(), git.shortSHA("master")) ret = grapeMenu.menu().applyMenuChoice("md", ["--am"]) self.assertFalse( ret, "grape m did not return false as expected for a conflict") # resolve the conflict self.assertFalse( git.isWorkingDirectoryClean(), "working directory clean before attempted continution of " "merge\n %s" % self.output.getvalue()) git.checkout("--ours f2") git.add("f2") ret = grapeMenu.menu().applyMenuChoice("md", ["--continue"]) self.assertTrue( ret, "grape md --continue did not return True\n%s" % self.output.getvalue()) self.assertTrue( git.isWorkingDirectoryClean(), "grape m --continue did not finish merge\n%s" % self.output.getvalue()) except SystemExit: self.fail("Unexpected SystemExit: %s" % self.output.getvalue())
def testPush(self): try: os.chdir(self.repo) f2name = os.path.join(self.repo, "f2") writeFile2(f2name) git.add(f2name) git.commit(" -m \"initial commit for testPush\"") git.clone("%s %s" % (self.repo, self.repos[1])) git.checkout("-b testPush/tmpBranchToAllowPushesToMaster") os.chdir(self.repos[1]) f1name = os.path.join(self.repos[1], "f1") writeFile1(f1name) git.add("f1") commitStr = "testPush: added f1" git.commit(" -m \"%s\"" % commitStr) os.chdir(self.repo) log = git.log("--all") self.assertFalse(commitStr in log, "commit message in log before it should be") os.chdir(self.repos[1]) pushOutput = git.push("origin master") os.chdir(self.repo) git.checkout("master") log = git.log() self.assertTrue(commitStr in log, "commit message not in log after push") except git.GrapeGitError as error: self.handleGitError(error)
def testPush(self): try: os.chdir(self.repo) f2name = os.path.join(self.repo, "f2") writeFile2(f2name) git.add(f2name) git.commit(" -m \"initial commit for testPush\"") git.clone("%s %s" %(self.repo,self.repos[1])) git.checkout("-b testPush/tmpBranchToAllowPushesToMaster") os.chdir(self.repos[1]) f1name = os.path.join(self.repos[1],"f1") writeFile1(f1name) git.add("f1") commitStr = "testPush: added f1" git.commit(" -m \"%s\"" % commitStr) os.chdir(self.repo) log = git.log("--all") self.assertFalse(commitStr in log,"commit message in log before it should be") os.chdir(self.repos[1]) pushOutput = git.push("origin master") os.chdir(self.repo) git.checkout("master") log = git.log() self.assertTrue(commitStr in log, "commit message not in log after push") except git.GrapeGitError as error: self.handleGitError(error)
def assertCanAddNewSubproject(testGrapeObject): git.clone("--mirror %s %s" % (testGrapeObject.repo, testGrapeObject.repos[1])) os.chdir(testGrapeObject.repo) grapeMenu.menu().applyMenuChoice("addSubproject", ["--name=subproject1", "--prefix=subs/subproject1", "--branch=master", "--url=%s" % testGrapeObject.repos[1], "--nested", "--noverify"]) subproject1path = os.path.join(testGrapeObject.repo, "subs/subproject1") testGrapeObject.assertTrue(os.path.exists(subproject1path), "subproject1 does not exist") os.chdir(subproject1path) # check to see that subproject1 is a git repo basedir = os.path.split(git.baseDir())[-1] subdir = os.path.split(subproject1path)[-1] testGrapeObject.assertTrue(basedir == subdir, "subproject1's git repo is %s, not %s" % (basedir, subdir)) # check to see that edits that occur in the new subproject are ignored by outer repo testGrape.writeFile3(os.path.join(subproject1path, "f3")) # make sure there is an edit testGrapeObject.assertFalse(git.isWorkingDirectoryClean(), "subproject1 clean after adding f3") os.chdir(testGrapeObject.repo) # check that grape left the repository in a clean state testGrapeObject.assertTrue(git.isWorkingDirectoryClean(), "repo not clean after added subproject1") # check in the edit os.chdir(subproject1path) git.add("f3") git.commit("-m \"added f3\"") testGrapeObject.assertTrue(git.isWorkingDirectoryClean(), "subproject1 not clean") os.chdir(testGrapeObject.repo) testGrapeObject.subproject = subproject1path
def testTopicConfigOption(self): self.setUpBranchToFFMerge() git.checkout("-b someOtherBranch") testGrape.writeFile1("someOtherfile") git.add("someOtherfile") git.commit("-a -m \"someOtherfile\"") self.assertGrapePublishFailed(["--topic=testPublish"])
def setUpNonConflictingSubmoduleMerge(self): os.chdir(self.defaultWorkingDirectory) self.createTestSubmodule() git.branch("testSubmoduleMerge") # create a new commit in submodule1 os.chdir(os.path.join(self.repo, "submodule1")) git.checkout("master") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") # update outer level with new commit os.chdir(self.repo) git.commit( "submodule1 -m \"updated submodule gitlink on master branch\"") # setup what should be a notionally-conflict free merge # (grape needs to deal with the gitlink conflicts automatically) git.checkout("testSubmoduleMerge") git.submodule("update") os.chdir(os.path.join(self.repo, "submodule1")) git.checkout("-b testSubmoduleMerge") testGrape.writeFile3("f2") git.add("f2") git.commit("-m \"added f3 as f2\"") os.chdir(self.repo) git.commit("-a -m \"updated gitlink on branch testSubmoduleMerge\"") self.setUpConfig()
def setUpSubmoduleBranch(self): git.clone("%s %s" % (self.repo, self.repos[1])) os.chdir(self.repo) git.checkout("-b addSubmodule") git.submodule("add %s submodule" % self.repos[1]) git.commit("-m \"added submodule\"") git.push("origin HEAD") # put the remote for the submodule into a HEAD-less state so it can accept pushes os.chdir(self.repos[1]) git.checkout("--orphan HEAD") # go to the submodule and add a file to it. os.chdir(os.path.join(self.repo, "submodule")) f2 = os.path.join(self.repo, "submodule", "f2") testGrape.writeFile2(f2) git.checkout("-b addSubmodule") git.add(f2) git.commit("-m \"added f2\"") # add another file on the master branch for the submodule git.branch("-f master HEAD") git.checkout("master") f3 = os.path.join(self.repo, "submodule", "f3") testGrape.writeFile3(f3) git.add(f3) git.commit("f3 -m \"f3\"") # update the submodule's remote git.push("origin --all") # git back to the master branch in the original repository os.chdir(self.repo) git.checkout("master")
def setUpNonConflictingSubmoduleMerge(self): os.chdir(self.defaultWorkingDirectory) self.createTestSubmodule() git.branch("testSubmoduleMerge") # create a new commit in submodule1 os.chdir(os.path.join(self.repo, "submodule1")) git.checkout("master") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") # update outer level with new commit os.chdir(self.repo) git.commit("submodule1 -m \"updated submodule gitlink on master branch\"") # setup what should be a notionally-conflict free merge # (grape needs to deal with the gitlink conflicts automatically) git.checkout("testSubmoduleMerge") git.submodule("update") os.chdir(os.path.join(self.repo, "submodule1")) git.checkout("-b testSubmoduleMerge") testGrape.writeFile3("f2") git.add("f2") git.commit("-m \"added f3 as f2\"") os.chdir(self.repo) git.commit("-a -m \"updated gitlink on branch testSubmoduleMerge\"") self.setUpConfig()
def setUpSubmoduleBranch(self): git.clone("%s %s" % (self.repo, self.repos[1])) os.chdir(self.repo) git.checkout("-b addSubmodule") git.submodule("add %s submodule" % self.repos[1]) git.commit("-m \"added submodule\"") git.push("origin HEAD") # put the remote for the submodule into a HEAD-less state so it can accept pushes os.chdir(self.repos[1]) git.checkout("--orphan HEAD") # go to the submodule and add a file to it. os.chdir(os.path.join(self.repo,"submodule")) f2 = os.path.join(self.repo,"submodule","f2") testGrape.writeFile2(f2) git.checkout("-b addSubmodule") git.add(f2) git.commit("-m \"added f2\"") # add another file on the master branch for the submodule git.branch("-f master HEAD") git.checkout("master") f3 = os.path.join(self.repo, "submodule", "f3") testGrape.writeFile3(f3) git.add(f3) git.commit("f3 -m \"f3\"") # update the submodule's remote git.push("origin --all") # git back to the master branch in the original repository os.chdir(self.repo) git.checkout("master")
def setUpConflictingSubmoduleMerge(self): os.chdir(self.defaultWorkingDirectory) self.createTestSubmodule() git.branch("testSubmoduleMerge2") subPath = os.path.join(self.repo, "submodule1") os.chdir(subPath) git.branch("testSubmoduleMerge2") git.checkout("master") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") os.chdir(self.repo) git.commit( "submodule1 -m \"updated submodule gitlink on master branch\"") git.checkout("testSubmoduleMerge2") git.submodule("update") os.chdir(subPath) git.checkout("testSubmoduleMerge2") testGrape.writeFile3("f1") git.add("f1") git.commit("-m \"added f3 as f1\"") os.chdir(self.repo) git.commit( "submodule1 -m \"updated submodule gitlink on testSubmoduleMerge branch\"" ) self.setUpConfig()
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")
def setUpBranchToFFMerge(self): os.chdir(self.repo) self.branch = "testPublish" git.checkout("-b %s" % self.branch) testGrape.writeFile2("f2") git.add("f2") git.commit("-m \"added f2\"") self.setUpConfig()
def setUpMerge(self): os.chdir(self.repo) # create a new branch git.branch("testMerge") # add f2 to master testGrape.writeFile2("f2") git.add("f2") git.commit("-m \"f2\"") git.checkout("testMerge") self.setUpConfig()
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())
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)
def testCommit(self): try: os.chdir(self.repo) f1name = os.path.join(self.repo,"f1") writeFile1(f1name) commitStr = "testCommit: added f1" git.add("f1") git.commit("f1 -m \"%s\"" % commitStr) log = git.log() self.assertTrue(commitStr in log) except git.GrapeGitError as error: self.handleGitError(error)
def testCommit(self): try: os.chdir(self.repo) f1name = os.path.join(self.repo, "f1") writeFile1(f1name) commitStr = "testCommit: added f1" git.add("f1") git.commit("f1 -m \"%s\"" % commitStr) log = git.log() self.assertTrue(commitStr in log) except git.GrapeGitError as error: self.handleGitError(error)
def setUpConflictingNestedSubprojectMerge(self): os.chdir(self.defaultWorkingDirectory) testNestedSubproject.TestNestedSubproject.assertCanAddNewSubproject(self) os.chdir(self.subproject) # set up f1 with conflicting content on master and testNestedMerge branches. git.checkout("master") git.branch("testNestedMerge") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") git.checkout("testNestedMerge") testGrape.writeFile3("f1") git.add("f1") git.commit("-m \"added f1 as f1\"") os.chdir(self.repo)
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"))
def setUpConflictingNestedSubprojectMerge(self): os.chdir(self.defaultWorkingDirectory) testNestedSubproject.TestNestedSubproject.assertCanAddNewSubproject( self) os.chdir(self.subproject) # set up f1 with conflicting content on master and testNestedMerge branches. git.checkout("master") git.branch("testNestedMerge") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") git.checkout("testNestedMerge") testGrape.writeFile3("f1") git.add("f1") git.commit("-m \"added f1 as f1\"") os.chdir(self.repo)
def testPull(self): try: git.clone("%s %s" %(self.repo,self.repos[1])) os.chdir(self.repo) f1name = os.path.join(self.repo,"f1") writeFile1(f1name) git.add("f1") commitStr = "testPull: added f1" git.commit(" -m \"%s\"" % commitStr) os.chdir(self.repos[1]) log = git.log("--all") self.assertFalse(commitStr in log,"commit message in log before it should be") git.pull("origin master") log = git.log() self.assertTrue(commitStr in log, "commit message not in log after pull") except git.GrapeGitError as error: self.handleGitError(error)
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())
def testConflictingMerge_MD(self): self.setUpConflictingMerge() try: self.assertNotEqual(git.shortSHA(), git.shortSHA("master")) ret = grapeMenu.menu().applyMenuChoice("md", ["--am"]) self.assertFalse(ret, "grape m did not return false as expected for a conflict") # resolve the conflict self.assertFalse(git.isWorkingDirectoryClean(), "working directory clean before attempted continution of " "merge\n %s" % self.output.getvalue()) git.checkout("--ours f2") git.add("f2") ret = grapeMenu.menu().applyMenuChoice("md", ["--continue"]) self.assertTrue(ret, "grape md --continue did not return True\n%s" % self.output.getvalue()) self.assertTrue(git.isWorkingDirectoryClean(), "grape m --continue did not finish merge\n%s" % self.output.getvalue()) except SystemExit: self.fail("Unexpected SystemExit: %s" % self.output.getvalue())
def testPull(self): try: git.clone("%s %s" % (self.repo, self.repos[1])) os.chdir(self.repo) f1name = os.path.join(self.repo, "f1") writeFile1(f1name) git.add("f1") commitStr = "testPull: added f1" git.commit(" -m \"%s\"" % commitStr) os.chdir(self.repos[1]) log = git.log("--all") self.assertFalse(commitStr in log, "commit message in log before it should be") git.pull("origin master") log = git.log() self.assertTrue(commitStr in log, "commit message not in log after pull") except git.GrapeGitError as error: self.handleGitError(error)
def testRebase(self): try: os.chdir(self.repo) f1name = os.path.join(self.repo,"f1") writeFile1(f1name) git.add(f1name) git.commit("-m \"initial commit\"") git.branch("testRebase/branchToRebase HEAD") # while still on master add another commit. writeFile2(f1name) git.add(f1name) git.commit("-m \"edited f1\"") # switch to new branch, add a new file, commit, rebase onto master. git.checkout("testRebase/branchToRebase") f2name = os.path.join(self.repo,"f2") writeFile2(f2name) git.add(f2name) git.commit("-m \"added f2\" ") self.assertFalse(git.branchUpToDateWith("testRebase/branchToRebase","master"),"attempting rebase in situation where rebase will not do anything.") try: git.rebase("master") self.assertTrue(git.branchUpToDateWith("testRebase/branchToRebase","master"),"rebase did not bring current branch up to date with master") except git.GrapeGitError as error: self.assertTrue(False,"rebase that should not have generated a conflict failed") except git.GrapeGitError as error: self.handleGitError(error)
def testRebase(self): try: os.chdir(self.repo) f1name = os.path.join(self.repo, "f1") writeFile1(f1name) git.add(f1name) git.commit("-m \"initial commit\"") git.branch("testRebase/branchToRebase HEAD") # while still on master add another commit. writeFile2(f1name) git.add(f1name) git.commit("-m \"edited f1\"") # switch to new branch, add a new file, commit, rebase onto master. git.checkout("testRebase/branchToRebase") f2name = os.path.join(self.repo, "f2") writeFile2(f2name) git.add(f2name) git.commit("-m \"added f2\" ") self.assertFalse( git.branchUpToDateWith("testRebase/branchToRebase", "master"), "attempting rebase in situation where rebase will not do anything." ) try: git.rebase("master") self.assertTrue( git.branchUpToDateWith("testRebase/branchToRebase", "master"), "rebase did not bring current branch up to date with master" ) except git.GrapeGitError as error: self.assertTrue( False, "rebase that should not have generated a conflict failed") except git.GrapeGitError as error: self.handleGitError(error)
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
def setUpConflictingSubmoduleMerge(self): os.chdir(self.defaultWorkingDirectory) self.createTestSubmodule() git.branch("testSubmoduleMerge2") subPath = os.path.join(self.repo, "submodule1") os.chdir(subPath) git.branch("testSubmoduleMerge2") git.checkout("master") testGrape.writeFile2("f1") git.add("f1") git.commit("-m \"added f2 as f1\"") os.chdir(self.repo) git.commit("submodule1 -m \"updated submodule gitlink on master branch\"") git.checkout("testSubmoduleMerge2") git.submodule("update") os.chdir(subPath) git.checkout("testSubmoduleMerge2") testGrape.writeFile3("f1") git.add("f1") git.commit("-m \"added f3 as f1\"") os.chdir(self.repo) git.commit("submodule1 -m \"updated submodule gitlink on testSubmoduleMerge branch\"") self.setUpConfig()
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"))
def assertCanAddNewSubproject(testGrapeObject): git.clone("--mirror %s %s" % (testGrapeObject.repo, testGrapeObject.repos[1])) os.chdir(testGrapeObject.repo) grapeMenu.menu().applyMenuChoice("addSubproject", [ "--name=subproject1", "--prefix=subs/subproject1", "--branch=master", "--url=%s" % testGrapeObject.repos[1], "--nested", "--noverify" ]) subproject1path = os.path.join(testGrapeObject.repo, "subs/subproject1") testGrapeObject.assertTrue(os.path.exists(subproject1path), "subproject1 does not exist") os.chdir(subproject1path) # check to see that subproject1 is a git repo basedir = os.path.split(git.baseDir())[-1] subdir = os.path.split(subproject1path)[-1] testGrapeObject.assertTrue( basedir == subdir, "subproject1's git repo is %s, not %s" % (basedir, subdir)) # check to see that edits that occur in the new subproject are ignored by outer repo testGrape.writeFile3(os.path.join(subproject1path, "f3")) # make sure there is an edit testGrapeObject.assertFalse(git.isWorkingDirectoryClean(), "subproject1 clean after adding f3") os.chdir(testGrapeObject.repo) # check that grape left the repository in a clean state testGrapeObject.assertTrue(git.isWorkingDirectoryClean(), "repo not clean after added subproject1") # check in the edit os.chdir(subproject1path) git.add("f3") git.commit("-m \"added f3\"") testGrapeObject.assertTrue(git.isWorkingDirectoryClean(), "subproject1 not clean") os.chdir(testGrapeObject.repo) testGrapeObject.subproject = subproject1path
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")
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)
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)
def setUpConflictingMerge(self): self.setUpMerge() # add a conflicting commit testGrape.writeFile3("f2") git.add("f2") git.commit("-m \"f2\"")