Beispiel #1
0
 def test_git_subdir_is_dirty_modified_outside(self):
     with open(join(REPODIR, 'ignored_in_root.txt'), 'a') as f:
         f.write("\nmore content\n")
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #2
0
 def test_git_is_dirty_modified(self):
     with open(join(REPODIR, 'subdir/to_be_kept.txt'), 'a') as f:
         f.write("\nmore content\n")
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #3
0
 def test_git_subdir_is_dirty_added_outside(self):
     makefile('added.txt', 'this will be added')
     self._git_add(['added.txt'])
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
 def test_commit_filename_with_spaces(self):
     """See issue #79 (https://github.com/data-workspaces/data-workspaces-core/issues/79)
     Files with spaces returned by git status --porcelain are in quotes!
     """
     os.mkdir(join(REPODIR, 'subdir'))
     makefile('subdir/to_be_deleted.txt', 'this file will be deleted')
     makefile('subdir/to_be_left_alone.txt', 'this file to be left alone')
     makefile('subdir/to be modified.txt', 'this file to be modified')
     makefile('root_file1.txt', 'this should not be changed')
     self._git_add([
         'subdir/to_be_deleted.txt', 'subdir/to_be_left_alone.txt',
         'subdir/to be modified.txt', 'root_file1.txt'
     ])
     self._run(['commit', '-m', 'initial version'])
     os.remove(join(REPODIR, 'subdir/to_be_deleted.txt'))
     with open(join(REPODIR, 'subdir/to be modified.txt'), 'a') as f:
         f.write("Adding another line to file!\n")
     makefile('subdir/to_be_added.txt', 'this file was added')
     commit_changes_in_repo_subdir(REPODIR,
                                   'subdir',
                                   'testing applied changes',
                                   verbose=True)
     self.assertFalse(is_git_dirty(REPODIR),
                      "Git still dirty after commit!")
     self.assert_file_exists('subdir/to_be_left_alone.txt')
     self.assert_file_exists('subdir/to be modified.txt')
     self.assert_file_exists('subdir/to_be_added.txt')
     self.assert_file_not_exists('subdir/to_be_deleted.txt')
     self.assert_file_exists('root_file1.txt')
     # verify that staged files outside of the subdir are not changed
     makefile('staged_but_not_committed.txt',
              'should be staged but not committed')
     self._git_add(['staged_but_not_committed.txt'])
     commit_changes_in_repo_subdir(REPODIR,
                                   'subdir',
                                   'testing not committing',
                                   verbose=True)
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #5
0
 def test_commit(self):
     os.mkdir(join(REPODIR, 'subdir'))
     makefile('subdir/to_be_deleted.txt', 'this file will be deleted')
     makefile('subdir/to_be_left_alone.txt', 'this file to be left alone')
     makefile('subdir/to_be_modified.txt', 'this file to be modified')
     makefile('root_file1.txt', 'this should not be changed')
     self._git_add([
         'subdir/to_be_deleted.txt', 'subdir/to_be_left_alone.txt',
         'subdir/to_be_modified.txt', 'root_file1.txt'
     ])
     self._run(['commit', '-m', 'initial version'])
     os.remove(join(REPODIR, 'subdir/to_be_deleted.txt'))
     with open(join(REPODIR, 'subdir/to_be_modified.txt'), 'a') as f:
         f.write("Adding another line to file!\n")
     makefile('subdir/to_be_added.txt', 'this file was added')
     commit_changes_in_repo_subdir(REPODIR,
                                   'subdir',
                                   'testing applied changes',
                                   verbose=True)
     self.assertFalse(is_git_dirty(REPODIR),
                      "Git still dirty after commit!")
     self.assert_file_exists('subdir/to_be_left_alone.txt')
     self.assert_file_exists('subdir/to_be_modified.txt')
     self.assert_file_exists('subdir/to_be_added.txt')
     self.assert_file_not_exists('subdir/to_be_deleted.txt')
     self.assert_file_exists('root_file1.txt')
     # verify that staged files outside of the subdir are not changed
     makefile('staged_but_not_committed.txt',
              'should be staged but not committed')
     self._git_add(['staged_but_not_committed.txt'])
     commit_changes_in_repo_subdir(REPODIR,
                                   'subdir',
                                   'testing not committing',
                                   verbose=True)
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
    def pull_workspace(self) -> ws.SyncedWorkspaceMixin:
        # first, check for problems
        if is_git_dirty(self.workspace_dir):
            raise ConfigurationError(
                "Data workspace metadata repo at %s has uncommitted changes. Please commit before pulling."
                % self.workspace_dir)
        validate_git_fat_in_path_if_needed(self.workspace_dir)

        # do the pulls
        branch = self.get_dws_git_branch()
        call_subprocess([GIT_EXE_PATH, "pull", "origin", branch],
                        cwd=self.workspace_dir,
                        verbose=self.verbose)
        run_git_fat_pull_if_needed(self.workspace_dir, self.verbose)

        # reload and return new workspace
        return Workspace(self.workspace_dir,
                         batch=self.batch,
                         verbose=self.verbose)
Beispiel #7
0
 def test_commit(self):
     makefile('to_be_deleted.txt', 'this file will be deleted')
     makefile('to_be_left_alone.txt', 'this file to be left alone')
     makefile('to_be_modified.txt', 'this file to be modified')
     self._git_add([
         'to_be_deleted.txt', 'to_be_left_alone.txt', 'to_be_modified.txt'
     ])
     self._run(['commit', '-m', 'initial version'])
     os.remove(join(REPODIR, 'to_be_deleted.txt'))
     with open(join(REPODIR, 'to_be_modified.txt'), 'a') as f:
         f.write("Adding another line to file!\n")
     makefile('to_be_added.txt', 'this file was added')
     commit_changes_in_repo(REPODIR,
                            'testing applied changes',
                            verbose=True)
     self.assertFalse(is_git_dirty(REPODIR),
                      "Git still dirty after commit!")
     self.assert_file_exists('to_be_left_alone.txt')
     self.assert_file_exists('to_be_modified.txt')
     self.assert_file_exists('to_be_added.txt')
     self.assert_file_not_exists('to_be_deleted.txt')
 def _push_precheck(
         self, resource_list: List[ws.LocalStateResourceMixin]) -> None:
     branch = self.get_dws_git_branch()
     if is_pull_needed_from_remote(self.workspace_dir, branch,
                                   self.verbose):
         raise ConfigurationError(
             "Data workspace at %s requires a pull from remote origin" %
             self.workspace_dir)
     validate_git_fat_in_path_if_needed(self.workspace_dir)
     if is_git_dirty(self.workspace_dir):
         if not self.batch:
             click.echo(
                 "Database workspace metadata repo at %s has uncommitted changes:"
                 % self.workspace_dir)
             echo_git_status_for_user(self.workspace_dir)
             click.confirm("Do you wish to continue anyway?", abort=True)
         else:
             raise ConfigurationError(
                 "Data workspace metadata repo at %s has uncommitted changes. Please commit before pushing."
                 % self.workspace_dir)
     super()._push_precheck(resource_list)
 def test_commit_filename_with_spaces(self):
     """See issue #79 (https://github.com/data-workspaces/data-workspaces-core/issues/79)
     Files with spaces returned by git status --porcelain are in quotes!
     """
     makefile('to_be_deleted.txt', 'this file will be deleted')
     makefile('to_be_left_alone.txt', 'this file to be left alone')
     makefile('to be modified.txt', 'this file to be modified')
     self._git_add([
         'to_be_deleted.txt', 'to_be_left_alone.txt', 'to be modified.txt'
     ])
     self._run(['commit', '-m', 'initial version'])
     os.remove(join(REPODIR, 'to_be_deleted.txt'))
     with open(join(REPODIR, 'to be modified.txt'), 'a') as f:
         f.write("Adding another line to file!\n")
     makefile('to_be_added.txt', 'this file was added')
     commit_changes_in_repo(REPODIR,
                            'testing applied changes',
                            verbose=True)
     self.assertFalse(is_git_dirty(REPODIR),
                      "Git still dirty after commit!")
     self.assert_file_exists('to_be_left_alone.txt')
     self.assert_file_exists('to be modified.txt')
     self.assert_file_exists('to_be_added.txt')
     self.assert_file_not_exists('to_be_deleted.txt')
Beispiel #10
0
 def test_git_is_dirty_clean(self):
     self.assertFalse(is_git_dirty(REPODIR))
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #11
0
    def test_checkout_and_apply_commit(self):
        # First, do all the setup
        os.mkdir(join(REPODIR, 'subdir'))
        makefile('subdir/to_be_deleted.txt', 'this file will be deleted')
        makefile('subdir/to_be_left_alone.txt', 'this file to be left alone')
        makefile('subdir/to_be_modified.txt', 'this file to be modified\n')
        makefile('root_file1.txt', 'root file v1\n')
        self._git_add([
            'subdir/to_be_deleted.txt', 'subdir/to_be_left_alone.txt',
            'subdir/to_be_modified.txt', 'root_file1.txt'
        ])
        self._run(['commit', '-m', 'initial version'])
        initial_hash = get_local_head_hash(REPODIR, True)
        subdir_hash = get_subdirectory_hash(REPODIR, 'subdir', verbose=True)

        self._run(['rm', 'subdir/to_be_deleted.txt'])
        with open(join(REPODIR, 'subdir/to_be_modified.txt'), 'a') as f:
            f.write("Adding another line to file!\n")
        makefile('subdir/to_be_added.txt', 'this file was added')
        with open(join(REPODIR, 'root_file1.txt'), 'a') as f:
            f.write("root file v2")
        self._git_add([
            'subdir/to_be_modified.txt', 'subdir/to_be_added.txt',
            'root_file1.txt'
        ])
        self._run(['commit', '-m', 'second version'])
        second_hash = get_local_head_hash(REPODIR, True)

        makefile('subdir/added_in_third_commit.txt', 'added in third commit')
        with open(join(REPODIR, 'subdir/to_be_modified.txt'), 'a') as f:
            f.write("Adding a third to file!\n")
        self._git_add(
            ['subdir/added_in_third_commit.txt', 'subdir/to_be_modified.txt'])
        self._run(['commit', '-m', 'third version'])
        third_hash = get_local_head_hash(REPODIR, True)

        # now, revert back to the first commit
        checkout_subdir_and_apply_commit(REPODIR, 'subdir', initial_hash, True)
        self.assertFalse(is_git_dirty(REPODIR),
                         "Git still dirty after commit!")
        self.assert_file_exists("subdir/to_be_deleted.txt")
        self.assert_file_not_exists("subdir/to_be_added.txt")
        self.assert_file_not_exists("subdir/added_in_third_commit.txt")
        self.assert_file_contents_equal("subdir/to_be_modified.txt",
                                        "this file to be modified")
        self.assert_file_contents_equal("root_file1.txt",
                                        "root file v1\nroot file v2")
        restored_hash = get_local_head_hash(REPODIR, True)
        self.assertNotEqual(initial_hash, restored_hash)  # should be differemt
        restored_subdir_hash = get_subdirectory_hash(REPODIR,
                                                     'subdir',
                                                     verbose=True)
        self.assertEqual(subdir_hash, restored_subdir_hash)

        # add a commit at this point
        with open(join(REPODIR, 'subdir/to_be_modified.txt'), 'a') as f:
            f.write("Overwritten after restoring first commit.")
        self._git_add(['subdir/to_be_modified.txt'])
        self._run(['commit', '-m', 'branch off first version'])

        # restore to third version
        checkout_subdir_and_apply_commit(REPODIR, 'subdir', third_hash, True)
        self.assertFalse(is_git_dirty(REPODIR),
                         "Git still dirty after commit!")
        self.assert_file_exists("subdir/added_in_third_commit.txt")
        self.assert_file_contents_equal(
            "subdir/to_be_modified.txt", 'this file to be modified\n' +
            "Adding another line to file!\n" + "Adding a third to file!")
        self.assert_file_not_exists("subdir/to_be_deleted.txt")
        self.assert_file_contents_equal("root_file1.txt",
                                        "root file v1\nroot file v2")

        # revert to restored hash and verify changes
        checkout_subdir_and_apply_commit(REPODIR, 'subdir', restored_hash,
                                         True)
        self.assertFalse(is_git_dirty(REPODIR),
                         "Git still dirty after commit!")
        self.assert_file_exists("subdir/to_be_deleted.txt")
        self.assert_file_not_exists("subdir/to_be_added.txt")
        self.assert_file_not_exists("subdir/added_in_third_commit.txt")
        self.assert_file_contents_equal("subdir/to_be_modified.txt",
                                        "this file to be modified")
        self.assert_file_contents_equal("root_file1.txt",
                                        "root file v1\nroot file v2")

        # run again with the same hash. It should do nothing, as there
        # are no changes
        checkout_subdir_and_apply_commit(REPODIR, 'subdir', restored_hash,
                                         True)
Beispiel #12
0
 def test_git_subdir_is_dirty_deleted_in_staging_outside(self):
     self._run(['rm', 'ignored_in_root.txt'])
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #13
0
 def test_git_subdir_is_dirty_deleted_outside(self):
     os.remove(join(REPODIR, 'ignored_in_root.txt'))
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #14
0
 def test_git_subdir_is_dirty_untracked_outside(self):
     makefile('untracked.txt', 'this is untracked')
     self.assertFalse(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #15
0
 def test_git_is_dirty_deleted_in_staging(self):
     self._run(['rm', 'subdir/to_be_deleted.txt'])
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertTrue(is_git_staging_dirty(REPODIR))
     self.assertTrue(is_git_staging_dirty(REPODIR, 'subdir'))
Beispiel #16
0
 def test_git_is_dirty_deleted(self):
     os.remove(join(REPODIR, 'subdir/to_be_deleted.txt'))
     self.assertTrue(is_git_dirty(REPODIR))
     self.assertTrue(is_git_subdir_dirty(REPODIR, 'subdir'))
     self.assertFalse(is_git_staging_dirty(REPODIR))
     self.assertFalse(is_git_staging_dirty(REPODIR, 'subdir'))