Beispiel #1
0
    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())
Beispiel #2
0
    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())
Beispiel #3
0
    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())
Beispiel #4
0
    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')
Beispiel #5
0
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)
        else:
            # Check if patch already exists, if it does, issue a warning and
            # give the user an option to overwrite the patch.
            while args.patch_name in stash.get_patches():
                yes_no_answer = input("Warning, patch '%s' already exists, overwrite [Y/n]? " % args.patch_name)
                if not yes_no_answer or yes_no_answer.lower() == "y":
                    stash.remove_patch(args.patch_name)
                elif yes_no_answer.lower() == "n":
                    args.patch_name = None
                    while not args.patch_name: