|
13 | 13 | _get_default_branches_for_merge_base, |
14 | 14 | calculate_pre_push_commit_range, |
15 | 15 | calculate_pre_receive_commit_range, |
| 16 | + collect_commit_range_diff_documents, |
16 | 17 | get_diff_file_path, |
17 | 18 | get_safe_head_reference_for_diff, |
18 | 19 | parse_commit_range, |
@@ -846,40 +847,40 @@ def test_two_dot_linear_history(self) -> None: |
846 | 847 | with temporary_git_repository() as (temp_dir, repo): |
847 | 848 | a, b, c = self._make_linear_history(repo, temp_dir) |
848 | 849 |
|
849 | | - parsed_from, parsed_to = parse_commit_range(f'{a}..{c}', temp_dir) |
850 | | - assert (parsed_from, parsed_to) == (a, c) |
| 850 | + parsed_from, parsed_to, separator = parse_commit_range(f'{a}..{c}', temp_dir) |
| 851 | + assert (parsed_from, parsed_to, separator) == (a, c, '..') |
851 | 852 |
|
852 | 853 | def test_three_dot_linear_history(self) -> None: |
853 | 854 | """For 'A...C' in linear history, expect (A,C).""" |
854 | 855 | with temporary_git_repository() as (temp_dir, repo): |
855 | 856 | a, b, c = self._make_linear_history(repo, temp_dir) |
856 | 857 |
|
857 | | - parsed_from, parsed_to = parse_commit_range(f'{a}...{c}', temp_dir) |
858 | | - assert (parsed_from, parsed_to) == (a, c) |
| 858 | + parsed_from, parsed_to, separator = parse_commit_range(f'{a}...{c}', temp_dir) |
| 859 | + assert (parsed_from, parsed_to, separator) == (a, c, '...') |
859 | 860 |
|
860 | 861 | def test_open_right_linear_history(self) -> None: |
861 | 862 | """For 'A..', expect (A,HEAD=C).""" |
862 | 863 | with temporary_git_repository() as (temp_dir, repo): |
863 | 864 | a, b, c = self._make_linear_history(repo, temp_dir) |
864 | 865 |
|
865 | | - parsed_from, parsed_to = parse_commit_range(f'{a}..', temp_dir) |
866 | | - assert (parsed_from, parsed_to) == (a, c) |
| 866 | + parsed_from, parsed_to, separator = parse_commit_range(f'{a}..', temp_dir) |
| 867 | + assert (parsed_from, parsed_to, separator) == (a, c, '..') |
867 | 868 |
|
868 | 869 | def test_open_left_linear_history(self) -> None: |
869 | 870 | """For '..C' where HEAD==C, expect (HEAD=C,C).""" |
870 | 871 | with temporary_git_repository() as (temp_dir, repo): |
871 | 872 | a, b, c = self._make_linear_history(repo, temp_dir) |
872 | 873 |
|
873 | | - parsed_from, parsed_to = parse_commit_range(f'..{c}', temp_dir) |
874 | | - assert (parsed_from, parsed_to) == (c, c) |
| 874 | + parsed_from, parsed_to, separator = parse_commit_range(f'..{c}', temp_dir) |
| 875 | + assert (parsed_from, parsed_to, separator) == (c, c, '..') |
875 | 876 |
|
876 | 877 | def test_single_commit_spec(self) -> None: |
877 | 878 | """For 'A', expect (A,HEAD=C).""" |
878 | 879 | with temporary_git_repository() as (temp_dir, repo): |
879 | 880 | a, b, c = self._make_linear_history(repo, temp_dir) |
880 | 881 |
|
881 | | - parsed_from, parsed_to = parse_commit_range(a, temp_dir) |
882 | | - assert (parsed_from, parsed_to) == (a, c) |
| 882 | + parsed_from, parsed_to, separator = parse_commit_range(a, temp_dir) |
| 883 | + assert (parsed_from, parsed_to, separator) == (a, c, '..') |
883 | 884 |
|
884 | 885 |
|
885 | 886 | class TestParsePreReceiveInput: |
@@ -1047,3 +1048,58 @@ def test_initial_oldest_commit_without_parent_with_two_commits_returns_single_co |
1047 | 1048 | work_repo.close() |
1048 | 1049 | finally: |
1049 | 1050 | server_repo.close() |
| 1051 | + |
| 1052 | + |
| 1053 | +class TestCollectCommitRangeDiffDocuments: |
| 1054 | + """Test the collect_commit_range_diff_documents function with various commit range formats.""" |
| 1055 | + |
| 1056 | + def test_collect_with_various_commit_range_formats(self) -> None: |
| 1057 | + """Test that different commit range formats are normalized and work correctly.""" |
| 1058 | + with temporary_git_repository() as (temp_dir, repo): |
| 1059 | + # Create three commits |
| 1060 | + a_file = os.path.join(temp_dir, 'a.txt') |
| 1061 | + with open(a_file, 'w') as f: |
| 1062 | + f.write('A') |
| 1063 | + repo.index.add(['a.txt']) |
| 1064 | + a_commit = repo.index.commit('A') |
| 1065 | + |
| 1066 | + with open(a_file, 'a') as f: |
| 1067 | + f.write('B') |
| 1068 | + repo.index.add(['a.txt']) |
| 1069 | + b_commit = repo.index.commit('B') |
| 1070 | + |
| 1071 | + with open(a_file, 'a') as f: |
| 1072 | + f.write('C') |
| 1073 | + repo.index.add(['a.txt']) |
| 1074 | + c_commit = repo.index.commit('C') |
| 1075 | + |
| 1076 | + # Create mock context |
| 1077 | + mock_ctx = Mock() |
| 1078 | + mock_progress_bar = Mock() |
| 1079 | + mock_progress_bar.set_section_length = Mock() |
| 1080 | + mock_progress_bar.update = Mock() |
| 1081 | + mock_ctx.obj = {'progress_bar': mock_progress_bar} |
| 1082 | + |
| 1083 | + # Test two-dot range - should collect documents from commits B and C (2 commits, 2 documents) |
| 1084 | + commit_range = f'{a_commit.hexsha}..{c_commit.hexsha}' |
| 1085 | + documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range) |
| 1086 | + assert len(documents) == 2, f'Expected 2 documents from range A..C, got {len(documents)}' |
| 1087 | + commit_ids_in_documents = {doc.unique_id for doc in documents if doc.unique_id} |
| 1088 | + assert b_commit.hexsha in commit_ids_in_documents |
| 1089 | + assert c_commit.hexsha in commit_ids_in_documents |
| 1090 | + |
| 1091 | + # Test three-dot range - should collect documents from commits B and C (2 commits, 2 documents) |
| 1092 | + commit_range = f'{a_commit.hexsha}...{c_commit.hexsha}' |
| 1093 | + documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range) |
| 1094 | + assert len(documents) == 2, f'Expected 2 documents from range A...C, got {len(documents)}' |
| 1095 | + |
| 1096 | + # Test parent notation with three-dot - should collect document from commit C (1 commit, 1 document) |
| 1097 | + commit_range = f'{c_commit.hexsha}~1...{c_commit.hexsha}' |
| 1098 | + documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range) |
| 1099 | + assert len(documents) == 1, f'Expected 1 document from range C~1...C, got {len(documents)}' |
| 1100 | + assert documents[0].unique_id == c_commit.hexsha |
| 1101 | + |
| 1102 | + # Test single commit spec - should be interpreted as A..HEAD (commits B and C, 2 documents) |
| 1103 | + commit_range = a_commit.hexsha |
| 1104 | + documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range) |
| 1105 | + assert len(documents) == 2, f'Expected 2 documents from single commit A, got {len(documents)}' |
0 commit comments