def _raw_git_clone(self, base_dir, url, branch, dest): clone_dir = _os.path.join(base_dir, dest) self._set_tear_down_cb(self._clone_tear_down_cb, clone_dir) ShellHelper.exec_command( _shlex.split('git clone -b %s %s %s' % (branch, url, dest)), base_dir) return
def test_current_tag_lightweight_tag(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.exec_command(_shlex.split('git tag tag-v1'), base_dir) git = GitWrapper(base_dir) self.assertEqual(git.get_current_tag(), 'tag-v1') return
def test_current_branch_detached_head(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.exec_command(_shlex.split('git checkout HEAD^'), base_dir) git = GitWrapper(base_dir) self.assertIsNone(git.get_current_branch()) return
def test_clone_no_write_permissions(self): base_dir = _os.path.join(type(self)._repos_dir, 'test-no-write') ShellHelper.make_dir(base_dir) _os.chmod(base_dir, _os.stat(base_dir).st_mode & ~(_stat.S_IWUSR)) with self.assertRaisesRegexp(GitWrapperError, r'^Command \'git clone -b .*\' failed$'): self._git_wrapper_clone_helper(base_dir, type(self)._origin_repo, 'master', 'test-clone', remove_base_dir=True) return
def test_untracked_with_files(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.append_text_to_file('Untracked file here...', 'untracked-test', base_dir) ShellHelper.append_text_to_file('Untracked file here too...', 'untracked-test2', base_dir) git = GitWrapper(base_dir) self.assertItemsEqual(git.get_untracked_files(), ['untracked-test', 'untracked-test2']) return
def test_unstaged_with_files(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.append_text_to_file('Modifying existing file...', 'README', base_dir) ShellHelper.remove_file(_os.path.join(base_dir, 'dummy')) git = GitWrapper(base_dir) self.assertItemsEqual(git.get_unstaged_files(), ['M\tREADME', 'D\tdummy']) return
def test_current_branch_invalid_repo(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') git_dir = _os.path.join(base_dir, '.git') ShellHelper.remove_dir(git_dir) git = GitWrapper(base_dir) with self.assertRaisesRegexp( GitWrapperError, r'^Command \'git symbolic-ref HEAD\' failed$'): git.get_current_branch() return
def test_update_index_invalid_repo(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') git_dir = _os.path.join(base_dir, '.git') ShellHelper.remove_dir(git_dir) with self.assertRaisesRegexp( GitWrapperError, r'^Command \'git update-index -q --ignore-submodules ' + r'--refresh\' failed$'): git = GitWrapper(base_dir) git.update_index() return
def test_clone_no_write_permissions(self): base_dir = _os.path.join( type(self)._repos_dir, 'test-no-write') ShellHelper.make_dir(base_dir) _os.chmod(base_dir, _os.stat(base_dir).st_mode & ~(_stat.S_IWUSR)) with self.assertRaisesRegexp( GitWrapperError, r'^Command \'git clone -b .*\' failed$'): self._git_wrapper_clone_helper( base_dir, type(self)._origin_repo, 'master', 'test-clone', remove_base_dir=True) return
def test_unstaged_with_files(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.append_text_to_file( 'Modifying existing file...', 'README', base_dir) ShellHelper.remove_file(_os.path.join(base_dir, 'dummy')) git = GitWrapper(base_dir) self.assertItemsEqual(git.get_unstaged_files(), ['M\tREADME', 'D\tdummy']) return
def test_untracked_with_files(self): self._raw_git_clone( type(self)._repos_dir, type(self)._origin_repo, 'master', 'test-clone') base_dir = _os.path.join(type(self)._repos_dir, 'test-clone') ShellHelper.append_text_to_file( 'Untracked file here...', 'untracked-test', base_dir) ShellHelper.append_text_to_file( 'Untracked file here too...', 'untracked-test2', base_dir) git = GitWrapper(base_dir) self.assertItemsEqual( git.get_untracked_files(), ['untracked-test', 'untracked-test2']) return
def _clone_tear_down_cb(self, clone_dir): ShellHelper.remove_dir(clone_dir) return
def tearDownClass(cls): if not cls._skip_cleanup: ShellHelper.remove_dir(cls._repos_dir) return
def __init__(self, base_test_dir): if not _os.path.isdir(base_test_dir): ShellHelper.make_dir(base_test_dir) GitWrapperTestCase.set_base_dir(base_test_dir) return