def test_get_patch(self): """Tests that it is possible to retrieve the contents of stashed patches. """ assert_equal(Stash.get_patch('a'), 'A') assert_equal(Stash.get_patch('b'), 'B') assert_equal(Stash.get_patch('c'), 'C')
def test_removing_patch(self): """Tests that it is possible to remove stashed patches.""" Stash.remove_patch('b') assert_equal(Stash.get_patches(), ['a', 'c']) Stash.remove_patch('c') assert_equal(Stash.get_patches(), ['a']) Stash.remove_patch('a') assert_equal(Stash.get_patches(), [])
def test_stash_and_apply_conflicting_change(self): """Test that applying a conflicting patch results in a merged file. """ stash = Stash(self.REPOSITORY_URI) # Modify a committed file. file_name = os.path.join(self.REPOSITORY_URI, 'a') f = open(file_name, 'w+') f.write('321') f.close() # Create the patch. stash.create_patch(self.PATCH_NAME) assert_in(self.PATCH_NAME, stash.get_patches()) # The file should again contain the original contents. assert_equal(open(file_name, 'r').read(), '123') # Modify the file such that it contains conflicting changes. f = open(file_name, 'w+') f.write('456') f.close() # Revert the changes to the file, and apply the patch to see whether we # get the expected result. stash.apply_patch(self.PATCH_NAME) # The file should contain the expected changes. assert_equal(open(file_name, 'r').read(), '<<<<<<<\n=======\n321\n>>>>>>>\n456') # Since the patch did not apply cleanly, the patch is not removed and # should still be present. assert_in(self.PATCH_NAME, stash.get_patches())
def test_stashing_removed_file(self): """Test that stashing a removed file will recreate it, and again remove it when applying the patch. """ stash = Stash(self.REPOSITORY_URI) # Remove a file from the repository. file_name = os.path.join(self.REPOSITORY_URI, 'b') stash.repository.remove(['b']) assert_true(not os.path.exists(file_name)) # Create the patch. stash.create_patch(self.PATCH_NAME) assert_in(self.PATCH_NAME, stash.get_patches()) # The removed file should exist again. assert_true(os.path.exists(file_name)) # Apply the patch, the file should exist again, and should have been # added to the repository. stash.apply_patch(self.PATCH_NAME) # The file that was removed should again be removed. assert_true(not os.path.exists(file_name)) # The patch applied cleanly, so it should no longer exist. assert_not_in(self.PATCH_NAME, stash.get_patches())
def test_stashing_added_file(self): """Test that stashing an added file will remove it, and again recreate it when applying the patch. """ stash = Stash(self.REPOSITORY_URI) # Create a new file. file_name = os.path.join(self.REPOSITORY_URI, 'd') f = open(file_name, 'w+') f.write('123') f.close() # Add the file to the repository. stash.repository.add(['d']) # Create the patch. stash.create_patch(self.PATCH_NAME) assert_in(self.PATCH_NAME, stash.get_patches()) # The newly created file should no longer exist. assert_true(not os.path.exists(file_name)) # Apply the patch, the file should exist again, and should have been # added to the repository. stash.apply_patch(self.PATCH_NAME) # The patch applied cleanly, so it should no longer exist. assert_not_in(self.PATCH_NAME, stash.get_patches())
def test_stash_and_apply_change(self): """Tests that it is possible to stash changes in a repository. """ stash = Stash(self.REPOSITORY_URI) # Modify a committed file. file_name = os.path.join(self.REPOSITORY_URI, 'a') f = open(file_name, 'w+') f.write('321') f.close() # Create the patch. stash.create_patch(self.PATCH_NAME) assert_in(self.PATCH_NAME, stash.get_patches()) # The file should contain the original contents. assert_equal(open(file_name, 'r').read(), '123') # Revert the changes to the file, and apply the patch to see whether we # get the expected result. stash.apply_patch(self.PATCH_NAME) # The file should contain the expected changes. assert_equal(open(file_name, 'r').read(), '321')
help="shows the contents of the specified patch from the stash", ) parser.add_argument( "-a", "--apply", dest="apply_patch", action="store_true", help="apply the specified patch in the stash, and remove it in case it applied successfully", ) parser.add_argument("patch_name", nargs="?", metavar="<patch name>", help="name of the patch to operate on") args = parser.parse_args() try: if args.show_list: for patch in Stash.get_patches(): print(patch) elif args.remove_patch: Stash.remove_patch(args.patch_name) print("Patch '%s' successfully removed." % args.patch_name) elif args.show_patch: print(Stash.get_patch(args.patch_name)) elif args.patch_name is not None: stash = Stash(os.getcwd()) if args.apply_patch: if stash.apply_patch(args.patch_name): print("Applying patch '%s' succeeded, stashed patch has been removed." % patch_name) else: # The patch did not apply cleanly, inform the user that the # patch will not be removed. print("Patch '%s' did not apply successfully, stashed patch will not be removed." % patch_name)
def test_get_patches(self): """Tests that it is possible to retrieve all stashed patches.""" assert_equal(Stash.get_patches(), ['a', 'b', 'c'])