def test_checkout(self):
        """Test whether Git checkout commands are correctly executed"""

        new_path = os.path.join(self.tmp_path, 'testworktree')

        repo = GraalRepository('http://example.git', self.git_path)
        self.assertIsNone(repo.worktreepath)
        repo.worktree(new_path)

        repo.checkout("075f0c6161db5a3b1c8eca45e08b88469bb148b9")
        current_commit_hash = self.__git_show_hash(repo)
        self.assertEqual("075f0c6161db5a3b1c8eca45e08b88469bb148b9",
                         current_commit_hash)

        repo.checkout("4f3b403d47fb291a9a942a62d62c24faa79244c8")
        current_commit_hash = self.__git_show_hash(repo)
        self.assertEqual("4f3b403d47fb291a9a942a62d62c24faa79244c8",
                         current_commit_hash)

        repo.checkout("825b4da7ca740f7f2abbae1b3402908a44d130cd")
        current_commit_hash = self.__git_show_hash(repo)
        self.assertEqual("825b4da7ca740f7f2abbae1b3402908a44d130cd",
                         current_commit_hash)

        repo.prune()
        self.assertFalse(os.path.exists(repo.worktreepath))
Exemple #2
0
print("Cloning stated..")

# Cloning the repo if it is not present
if not GraalRepository.exists(repo_dir):
    repo = GraalRepository.clone(repo_uri, repo_dir)
elif os.path.isdir(repo_dir):
    repo = GraalRepository(repo_uri, repo_dir)

# creating a new worktree if not already present
if GraalRepository.exists(worktreepath):
    shutil.rmtree(worktreepath)

repo.worktree(worktreepath)

# preforming checkout at given SHA
repo.checkout(sha)

print("cloning done")

# Using flake8 to find errors if any

flk_args = {
    'module_path': os.path.join(os.sep, 'tmp', 'fossology'),
    'worktree_path': '/tmp/worktrees',
    'details': True
}

# instantiating flake8
flake8 = Flake8()

check = flake8.analyze(**flk_args)
Exemple #3
0
worktree_path = input("Enter worktree path: ")
# Git object, pointing to repo_url and repo_dir for cloning
ggit = Git(uri=repo_url , gitpath=repo_dir)

# clone the repository (if it doesn't exist locally)
ggit.fetch_items(category='commit')

commits = list(ggit.fetch())
# hash of random commit
commit = random.choice(commits)
_hash = commit['data']['commit']
print(_hash)
# or input the hash of certain commit
# _hash = input("Enter hash: ")

gral_repo = GraalRepository(uri=repo_url, dirpath=repo_dir)

gral_repo.worktree(worktree_path)
# checkout the commit
gral_repo.checkout(_hash)
style_guide = flake8.get_style_guide()
files = worktree_path
# generate report by flake8
report = style_guide.check_files([files])
print(report.get_statistics(('E', 'W', 'F')))
print(report.total_errors)

# repo_url = https://github.com/chaoss/grimoirelab-perceval
# repo_dir = git/grimoirelab-perceval.git
# worktree_path = "/Users/tanxin/PycharmProjects/git"