Skip to content

Commit 4fa7c2b

Browse files
committed
Check if branch is a tag before trying to update
1 parent b4037a8 commit 4fa7c2b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

redbot/cogs/downloader/repo_manager.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Repo(RepoJSONMixin):
126126
"git -C {path} log --diff-filter=D --pretty=format:%H -n 1 {descendant_rev}"
127127
" -- {module_name}/__init__.py"
128128
)
129+
GIT_LIST_TAGS = "git -C {path} tag -l"
129130

130131
PIP_INSTALL = "{python} -m pip install -U -t {target_dir} {reqs}"
131132

@@ -247,6 +248,28 @@ async def is_on_branch(self) -> bool:
247248
"""
248249
return await self.latest_commit() == self.commit
249250

251+
async def is_branch_tag(self) -> bool:
252+
"""
253+
Check if the branch assosiated with the repo is a tag.
254+
255+
Returns
256+
-------
257+
bool
258+
`True` if branch is a tag or `False` otherwise
259+
"""
260+
git_command = ProcessFormatter().format(self.GIT_LIST_TAGS, path=self.folder_path)
261+
p = await self._run(git_command)
262+
263+
if p.returncode != 0:
264+
raise errors.GitException(
265+
"Git failed to get list of tags",
266+
git_command,
267+
)
268+
269+
tags = p.stdout.decode(**DECODE_PARAMS).strip().split("\n")
270+
271+
return self.branch in tags
272+
250273
async def _get_file_update_statuses(
251274
self, old_rev: str, new_rev: Optional[str] = None
252275
) -> Dict[str, str]:
@@ -815,6 +838,9 @@ async def update(self) -> Tuple[str, str]:
815838
-------
816839
`UpdateError` - if git pull results with non-zero exit code
817840
"""
841+
if await self.is_branch_tag():
842+
return self.commit, self.commit
843+
818844
old_commit = await self.latest_commit()
819845

820846
await self.hard_reset()

tests/cogs/downloader/test_downloader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ async def test_update(mocker, repo):
324324
new_commit = "a0ccc2390883c85a361f5a90c72e1b07958939fa"
325325
m = _mock_run(mocker, repo, 0)
326326
_mock_setup_repo(mocker, repo, new_commit)
327+
mocker.patch.object(repo, "is_branch_tag", autospec=True, return_value=False)
327328
mocker.patch.object(repo, "latest_commit", autospec=True, return_value=old_commit)
328329
mocker.patch.object(repo, "hard_reset", autospec=True, return_value=None)
329330
ret = await repo.update()

0 commit comments

Comments
 (0)