Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check commits even with shallow clone of tags #15023

Merged
merged 4 commits into from
Nov 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion conan/tools/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,23 @@ def commit_in_remote(self, commit, remote="origin"):
"""
if not remote:
return False
# Potentially do two checks here. If the clone is a shallow clone, then we won't be
# able to find the commit.
try:
branches = self.run("branch -r --contains {}".format(commit))
return "{}/".format(remote) in branches
if "{}/".format(remote) in branches:
return True
except Exception as e:
raise ConanException("Unable to check remote commit in '%s': %s" % (self.folder, str(e)))

try:
# This will raise if commit not present.
self.run("fetch {} --dry-run --depth=1 {}".format(remote, commit))
return True
except Exception as e:
# Don't raise an error because the fetch could fail for many more reasons than the branch.
return False

def is_dirty(self):
"""
Returns if the current folder is dirty, running ``git status -s``
Expand Down