| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5780812 commit 77b1135
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1042,11 +1042,19 @@ def active_branch(self) -> Head: | |||
| 1042 | 1042 | :raise TypeError: | |
| 1043 | 1043 | If HEAD is detached. | |
| 1044 | 1044 | ||
| 1045 | + :raise ValueError: | ||
| 1046 | + If HEAD points to the ``.invalid`` ref Git uses to mark refs as | ||
| 1047 | + incompatible with older clients. | ||
| 1048 | + | ||
| 1045 | 1049 | :return: | |
| 1046 | 1050 | :class:`~git.refs.head.Head` to the active branch | |
| 1047 | 1051 | """ | |
| 1048 | - # reveal_type(self.head.reference) # => Reference | ||
| 1049 | - return self.head.reference | ||
| 1052 | + active_branch = self.head.reference | ||
| 1053 | + if active_branch.name == ".invalid": | ||
| 1054 | + raise ValueError( | ||
| 1055 | + "HEAD points to 'refs/heads/.invalid', which Git uses to mark refs as incompatible with older clients" | ||
| 1056 | + ) | ||
| 1057 | + return active_branch | ||
| 1050 | 1058 | ||
| 1051 | 1059 | def blame_incremental(self, rev: str | HEAD | None, file: str, **kwargs: Any) -> Iterator["BlameEntry"]: | |
| 1052 | 1060 | """Iterator for blame information for the given file at the given revision. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -962,6 +962,46 @@ def test_empty_repo(self, rw_dir): | |||
| 962 | 962 | ||
| 963 | 963 | assert "BAD MESSAGE" not in contents, "log is corrupt" | |
| 964 | 964 | ||
| 965 | + @with_rw_directory | ||
| 966 | + def test_active_branch_raises_value_error_when_head_ref_is_invalid(self, rw_dir): | ||
| 967 | + repo = Repo.init(rw_dir) | ||
| 968 | + with open(osp.join(rw_dir, ".git", "HEAD"), "w") as f: | ||
| 969 | + f.write("ref: refs/heads/.invalid\n") | ||
| 970 | + | ||
| 971 | + self.assertRaisesRegex( | ||
| 972 | + ValueError, | ||
| 973 | + r"refs/heads/\.invalid.*older clients", | ||
| 974 | + lambda: repo.active_branch, | ||
| 975 | + ) | ||
| 976 | + | ||
| 977 | + @with_rw_directory | ||
| 978 | + def test_empty_repo_reftable_active_branch(self, rw_dir): | ||
| 979 | + git = Git(rw_dir) | ||
| 980 | + try: | ||
| 981 | + git.init(ref_format="reftable") | ||
| 982 | + except GitCommandError as err: | ||
| 983 | + if err.status == 129: | ||
| 984 | + pytest.skip("git init --ref-format is not supported by this git version") | ||
| 985 | + raise | ||
| 986 | + | ||
| 987 | + repo = Repo(rw_dir) | ||
| 988 | + self.assertEqual(repo.head.reference.name, ".invalid") | ||
| 989 | + self.assertRaisesRegex( | ||
| 990 | + ValueError, | ||
| 991 | + r"refs/heads/\.invalid.*older clients", | ||
| 992 | + lambda: repo.active_branch, | ||
| 993 | + ) | ||
| 994 | + | ||
| 995 | + @with_rw_directory | ||
| 996 | + def test_active_branch_raises_type_error_when_head_is_detached(self, rw_dir): | ||
| 997 | + repo = Repo.init(rw_dir) | ||
| 998 | + with open(osp.join(rw_dir, "a.txt"), "w") as f: | ||
| 999 | + f.write("a") | ||
| 1000 | + repo.index.add(["a.txt"]) | ||
| 1001 | + repo.index.commit("initial commit") | ||
| 1002 | + repo.git.checkout(repo.head.commit.hexsha) | ||
| 1003 | + self.assertRaisesRegex(TypeError, "detached symbolic reference", lambda: repo.active_branch) | ||
| 1004 | + | ||
| 965 | 1005 | def test_merge_base(self): | |
| 966 | 1006 | repo = self.rorepo | |
| 967 | 1007 | c1 = "f6aa8d1" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments