Skip to content

Commit

Permalink
Fix Git.get_url_and_commit raising for some Git configs (conan-io#1…
Browse files Browse the repository at this point in the history
…5271)

Fix dirty repo handling (conan-io#15261)
  • Loading branch information
Solviana authored and memsharded committed Dec 27, 2023
1 parent 665567d commit 22e8d6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit 22e8d6f

Please sign in to comment.