示例#1
0
def test_get_commits_last_modified_lines_hyper_blame(repo: Git):
    buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit(
        'e6d3b38a9ef683e8184eac10a0471075c2808bbd'))

    assert len(buggy_commits) == 1
    assert '540c7f31c18664a38190fafb6721b5174ff4a166' in buggy_commits[
        'B.java']
示例#2
0
    def _prep_repo(self, path_repo: str) -> Generator[Git, None, None]:
        local_path_repo = path_repo
        if self._is_remote(path_repo):
            local_path_repo = self._clone_remote_repo(self._clone_folder(),
                                                      path_repo)
        local_path_repo = str(Path(local_path_repo).expanduser().resolve())

        # when multiple repos are given in input, this variable will serve as a reminder
        # of which one we are currently analyzing
        self._conf.set_value('path_to_repo', local_path_repo)

        self.git = Git(local_path_repo, self._conf)
        # saving the Git object for further use
        self._conf.set_value("git", self.git)

        # checking that the filters are set correctly
        self._conf.sanity_check_filters()
        yield self.git

        # cleaning, this is necessary since GitPython issues on memory leaks
        self._conf.set_value("git", None)
        self.git.clear()
        self.git = None  # type: ignore

        # delete the temporary directory if created
        if self._is_remote(path_repo) and self._cleanup is True:
            assert self._tmp_dir is not None
            try:
                self._tmp_dir.cleanup()
            except PermissionError:
                # on Windows, Python 3.5, 3.6, 3.7 are not able to delete
                # git directories because of read-only files.
                # In this case, just ignore the errors.
                shutil.rmtree(self._tmp_dir.name, ignore_errors=True)
def test_source_code_before_complete(repo: Git):
    m1 = repo.get_commit('ca1f75455f064410360bc56218d0418221cf9484').modified_files[0]

    with open('test-repos/source_code_before_commit/'
              'sc_A_ca1f75455f064410360bc56218d0418221cf9484.txt') as f:
        sc = f.read()

    assert m1.source_code == sc
    assert m1.source_code_before is None

    old_sc = sc
    with open(
            'test-repos/source_code_before_commit/'
            'sc_A_022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0.txt') as f:
        sc = f.read()

    m1 = repo.get_commit('022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0').modified_files[0]

    assert m1.source_code == sc
    assert m1.source_code_before == old_sc

    old_sc = sc
    m1 = repo.get_commit('ecd6780457835a2fc85c532338a29f2c98a6cfeb').modified_files[0]

    assert m1.source_code is None
    assert m1.source_code_before == old_sc
def test_get_commits_last_modified_lines_rename(repo: Git):
    buggy_commits = repo.get_commits_last_modified_lines(
        repo.get_commit('2f2d0dec7cd06de4c2ed11ed010727a54af8ebf8'))

    assert len(buggy_commits) == 1
    assert '00e61714fd76ff110d8da953aa1179809591f5aa' in buggy_commits[str(
        Path('myfolder/Z.java'))]
def test_get_commits_last_modified_lines_rename_and_fix(repo: Git):
    buggy_commits = repo.get_commits_last_modified_lines(
        repo.get_commit('4e287ab8e6dba110219404fb8a43993f3dda674c'))

    assert len(buggy_commits) == 1
    assert '06b9ff31cd3475d9fd9ef668cc0844ab169da726' in buggy_commits[
        'H.java']
示例#6
0
def test_number_of_modified_files(repo: Git):
    commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')
    assert commit.modified_files[0].added_lines == 62
    assert commit.modified_files[0].deleted_lines == 0

    commit = repo.get_commit('d11dd6734ff4e60cac3a7b58d9267f138c9e05c7')
    assert commit.modified_files[0].added_lines == 1
    assert commit.modified_files[0].deleted_lines == 1
def test_equal(repo: Git):
    c1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2')
    c2 = repo.get_commit(c1.parents[0])
    c3 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58')

    assert c1.parents[0] == 'a4ece0762e797d2e2dcbd471115108dd6e05ff58'
    assert c3 == c2
    assert c1 != c3
示例#8
0
def test_tags(repo: Git):
    commit = repo.get_commit_from_tag('tag1')
    assert commit.hash == '6bb9e2c6a8080e6b5b34e6e316c894b2ddbf7fcd'

    commit = repo.get_commit_from_tag('tag2')
    assert commit.hash == '4638730126d40716e230c2040751a13153fb1556'

    with pytest.raises(IndexError):
        repo.get_commit_from_tag('tag4')
示例#9
0
def test_parent_commits(repo: Git):
    merge_commit = repo.get_commit('29e929fbc5dc6a2e9c620069b24e2a143af4285f')
    assert len(merge_commit.parents) == 2
    assert '8986af2a679759e5a15794f6d56e6d46c3f302f1' in merge_commit.parents
    assert '8169f76a3d7add54b4fc7bca7160d1f1eede6eda' in merge_commit.parents

    normal_commit = repo.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda')
    assert len(normal_commit.parents) == 1
    assert '168b3aab057ed61a769acf336a4ef5e64f76c9fd' in normal_commit.parents
示例#10
0
def test_merge_commits(repo: Git):
    commit = repo.get_commit("168b3aab057ed61a769acf336a4ef5e64f76c9fd")
    assert commit.merge is False

    commit = repo.get_commit("8169f76a3d7add54b4fc7bca7160d1f1eede6eda")
    assert commit.merge is False

    commit = repo.get_commit("29e929fbc5dc6a2e9c620069b24e2a143af4285f")
    assert commit.merge is True
示例#11
0
def test_get_commits_last_modified_lines_hyper_blame_unblamable(tmp_path, repo: Git):
    p = tmp_path / "ignore.txt"
    p.write_text("540c7f31c18664a38190fafb6721b5174ff4a166")

    buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit(
        'e6d3b38a9ef683e8184eac10a0471075c2808bbd'),
        hashes_to_ignore_path=str(p))

    assert len(buggy_commits) == 0
示例#12
0
def test_get_commits_last_modified_lines_hyper_blame_with_renaming(repo: Git):
    buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit(
        'be0772cbaa2eba32bf97aae885199d1a357ddc93'))

    assert len(buggy_commits) == 2
    assert '9568d20856728304ab0b4d2d02fb9e81d0e5156d' in buggy_commits[
        'A.java']
    assert '9568d20856728304ab0b4d2d02fb9e81d0e5156d' in buggy_commits[
        'H.java']
示例#13
0
def test_get_commits_last_modified_lines_multiple(repo: Git):
    buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('9942ee9dcdd1103e5808d544a84e6bc8cade0e54'))

    assert len(buggy_commits) == 1
    assert '2eb905e5e7be414fd184d6b4f1571b142621f4de' in buggy_commits[
        'A.java']
    assert '20a40688521c1802569e60f9d55342c3bfdd772c' in buggy_commits[
        'A.java']
    assert '22505e97dca6f843549b3a484b3609be4e3acf17' in buggy_commits[
        'A.java']
def test_eq_modifications(repo: Git):
    m1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').modified_files[0]
    m2 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').modified_files[0]
    m3 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58').modified_files[0]
    c1 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58')

    assert m1 == m2
    assert m1 == m1
    assert m1 != m3
    assert m1 != c1
示例#15
0
def test_branches_from_commit(repo: Git):
    commit = repo.get_commit('a997e9d400f742003dea601bb05a9315d14d1124')

    assert len(commit.branches) == 1
    assert 'b2' in commit.branches

    commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')
    assert len(commit.branches) == 2
    assert 'master' in commit.branches
    assert 'b2' in commit.branches
def test_eq_commit(repo: Git):
    c1 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a')
    c2 = repo.get_commit('09f6182cef737db02a085e1d018963c7a29bde5a')
    c3 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a')
    c4 = repo.get_commit('09f6182cef737db02a085e1d018963c7a29bde5a')
    assert c1 == c3
    assert c1 == c1
    assert c2 == c4
    assert c2 == c2
    assert c1 != c2
    assert c3 != c4
示例#17
0
def test_get_commits_last_modified_lines_for_single_file(repo: Git):
    commit = repo.get_commit('0f726924f96621e4965039123098ba83e39ffba6')
    buggy_commits = None
    for mod in commit.modified_files:
        if mod.filename == 'A.java':
            buggy_commits = repo.get_commits_last_modified_lines(commit, mod)

    assert buggy_commits
    assert len(buggy_commits) == 1
    assert 'e2ed043eb96c05ebde653a44ae733ded9ef90750' in buggy_commits['A.java']
    assert 1 == len(buggy_commits['A.java'])
示例#18
0
def test_get_commits_last_modified_lines_hyper_blame_ignore_hash(tmp_path, repo: Git):
    p = tmp_path / "ignore.txt"
    p.write_text("5cb9e9ae44a0949ec91d06a955975289be766f34")

    buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit(
        'c7002fb321a8ba32a28fac200538f7c2ba76f175'),
        hashes_to_ignore_path=str(p))

    assert len(buggy_commits) == 1
    assert 'c41d270f8abc203c895309235adbd5f3f81d4a45' in buggy_commits[
        'A.java']
示例#19
0
def test_modification_status(repo: Git):
    commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')
    assert commit.modified_files[0].change_type == ModificationType.ADD
    assert commit.modified_files[0].old_path is None

    commit = repo.get_commit('57dbd017d1a744b949e7ca0b1c1a3b3dd4c1cbc1')
    assert commit.modified_files[0].change_type == ModificationType.MODIFY
    assert commit.modified_files[0].new_path == commit.modified_files[0].old_path

    commit = repo.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71')
    assert commit.modified_files[0].change_type == ModificationType.DELETE
    assert commit.modified_files[0].new_path is None
示例#20
0
def test_other_branches_with_merge(repo: Git):
    commit = repo.get_commit('7203c0b8220dcc7a59614bc7549799cd203ac072')
    assert commit.in_main_branch is False

    commit = repo.get_commit('87a31153090808f1e6f679a14ea28729a0b74f4d')
    assert commit.in_main_branch is False

    commit = repo.get_commit('b197ef4f0b4bc5b7d55c8949ecb1c861731f0b9d')
    assert commit.in_main_branch is True

    commit = repo.get_commit('e51421e0beae6a3c20bdcdfc21066e05db675e03')
    assert commit.in_main_branch is True
示例#21
0
def test_commit_in_master_branch(repo: Git):
    assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f'

    repo.checkout('8986af2a679759e5a15794f6d56e6d46c3f302f1')

    git_to_change_head = Git('test-repos/branches_merged')
    commit = git_to_change_head.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda')
    assert commit.in_main_branch is False

    repo.reset()
    assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f'
示例#22
0
def test_get_head(repo: Git):
    assert repo is not None
    cs = repo.get_head()
    assert cs is not None

    assert cs.hash == 'da39b1326dbc2edfe518b90672734a08f3c13458'
    assert cs.author_date.timestamp() == 1522164679
def test_shortstats_add_and_del(repo: Git):
    c1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2')

    assert c1.insertions == 1
    assert c1.lines == 2
    assert c1.files == 1
    assert c1.deletions == 1
def test_shortstats_rename(repo: Git):
    c1 = repo.get_commit('da39b1326dbc2edfe518b90672734a08f3c13458')

    assert c1.insertions == 0
    assert c1.lines == 3
    assert c1.files == 1
    assert c1.deletions == 3
def test_shortstats_all_deletions(repo: Git):
    c1 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a')

    assert c1.insertions == 0
    assert c1.lines == 4
    assert c1.files == 1
    assert c1.deletions == 4
def test_shortstats_all_additions(repo: Git):
    c1 = repo.get_commit('a88c84ddf42066611e76e6cb690144e5357d132c')

    assert c1.insertions == 191
    assert c1.lines == 191
    assert c1.files == 2
    assert c1.deletions == 0
示例#27
0
def test_get_commits_modified_file(repo: Git):
    commits = repo.get_commits_modified_file('file2.java')

    assert len(commits) == 3
    assert '09f6182cef737db02a085e1d018963c7a29bde5a' in commits
    assert '6411e3096dd2070438a17b225f44475136e54e3a' in commits
    assert 'a88c84ddf42066611e76e6cb690144e5357d132c' in commits
示例#28
0
def test_get_tagged_commits(repo: Git):
    tagged_commits = repo.get_tagged_commits()

    assert len(tagged_commits) == 3
    assert '6bb9e2c6a8080e6b5b34e6e316c894b2ddbf7fcd' == tagged_commits[0]
    assert '4638730126d40716e230c2040751a13153fb1556' == tagged_commits[1]
    assert '627e1ad917a188a861c9fedf6e5858b79edbe439' == tagged_commits[2]
示例#29
0
def test_commit_dictset(repo: Git):
    c1 = repo.get_commit("e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2")
    c2 = repo.get_commit(c1.parents[0])
    c3 = repo.get_commit("a4ece0762e797d2e2dcbd471115108dd6e05ff58")

    commit_dict = {c1: c1.hash, c2: c2.hash, c3: c3.hash}

    assert type(commit_dict) == dict
    assert commit_dict[c1] == "e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2"
    assert commit_dict[c2] == c1.parents[0]
    assert commit_dict[c3] == "a4ece0762e797d2e2dcbd471115108dd6e05ff58"
    assert commit_dict[c1] != commit_dict[c2]

    commit_set = {c1, c2, c3}
    assert type(commit_set) == set
    assert c1 in commit_set
    assert commit_set - {c1} == {c2, c3}
def test_filepahs(repo: Git):
    c = repo.get_commit('f0f8aea2db50ed9f16332d86af3629ff7780583e')

    mod0 = c.modified_files[0]

    assert mod0.filename == 'a.java'
    assert mod0.new_path == str(Path('dir2/a.java'))
    assert mod0.old_path == str(Path('dir2/a.java'))