Example #1
0
 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
Example #2
0
 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
Example #3
0
    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
Example #4
0
    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
Example #5
0
    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
Example #6
0
    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
Example #7
0
    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
Example #8
0
    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
Example #9
0
    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
Example #10
0
    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
Example #11
0
    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
Example #12
0
    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
Example #13
0
    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
Example #14
0
    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
Example #15
0
    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
Example #16
0
    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
Example #17
0
 def _clone_tear_down_cb(self, clone_dir):
     ShellHelper.remove_dir(clone_dir)
     return
Example #18
0
 def tearDownClass(cls):
     if not cls._skip_cleanup:
         ShellHelper.remove_dir(cls._repos_dir)
     return
Example #19
0
 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
Example #20
0
 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
Example #21
0
 def tearDownClass(cls):
     if not cls._skip_cleanup:
         ShellHelper.remove_dir(cls._repos_dir)
     return
Example #22
0
 def _clone_tear_down_cb(self, clone_dir):
     ShellHelper.remove_dir(clone_dir)
     return