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

Fix Git.get_url_and_commit raising for some Git configs #15271

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion conan/tools/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def is_dirty(self):

:return: True, if the current folder is dirty. Otherwise, False.
"""
status = self.run(f"status . -s").strip()
status = self.run("status . --short --no-branch --untracked-files").strip()
return bool(status)

def get_url_and_commit(self, remote="origin"):
Expand Down
26 changes: 26 additions & 0 deletions conans/test/functional/tools/scm/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ def test_capture_remote_pushed_commit(self):
assert "pkg/0.1: SCM COMMIT: {}".format(new_commit) in c.out
assert "pkg/0.1: SCM URL: {}".format(url) in c.out

def test_capture_commit_modified_config(self):
"""
A clean repo with the status.branch git config set to on
Expected to not raise an error an return the commit and url
"""
folder = temp_folder()
url, commit = create_local_git_repo(files={"conanfile.py": self.conanfile}, folder=folder)
c = TestClient()
with c.chdir(folder):
c.run_command("git config --local status.branch true")
c.run("export .")
assert "pkg/0.1: SCM COMMIT: {}".format(commit) in c.out
assert "pkg/0.1: SCM URL: {}".format(url) in c.out

def test_capture_commit_modified_config_untracked(self):
"""
A dirty repo with the showUntrackedFiles git config set to off.
Expected to throw an exception
"""
folder = temp_folder()
url, commit = create_local_git_repo(files={"conanfile.py": self.conanfile}, folder=folder)
c = TestClient()
with c.chdir(folder):
c.save(files={"some_header.h": "now the repo is dirty"})
c.run_command("git config --local status.showUntrackedFiles no")
c.run("export .", assert_error=True)

@pytest.mark.tool("git")
class TestGitBasicClone:
Expand Down