Repository: conan-io/conan

Issue:
[bug] git.get_url_and_commit throws exception for different git configs
### Environment details

* Operating System+version: Ubuntu 22.04
* Compiler+version: n/a
* Conan version: Found on 1.59.0, all versions are affected
* Python version: 3.8.10


### Steps to reproduce

**1. Set git config "status.branch"** to true:

`git config --global status.branch true`

**2. Use Git.get_url_and_commit()** in your conanfile:
` 
from conan.tools.scm import Git

```
def export(self) -> None:
    git = Git(self, self.recipe_folder)
    scm_url, scm_commit = git.get_url_and_commit()   
   # Do something... 
```

**3. Execute conan create**. My example (copied from a python subprocess call):
```
'['conan', 'create', '-pr:b=ubuntu2004_x86_64_gcc8_debug', '-pr:h=ubuntu2004_x86_64_gcc8_debug', '-pr:h=cross_compiler_x86_64_linux_gcc8', '-pr:h=onep_bit', '/myrepo',
'0.20.2-alpha@user/dev'
```
**Observed result** (even though the repo is **not** dirty, I ran git clean -fd before):

```
Exporting package recipe
my_package/0.20.2-alpha@user/dev: Calling export()
ERROR: my_package/0.20.2-alpha@user/dev: Error in export() method, line 85
        scm_url, scm_commit = git.get_url_and_commit()
        ConanException: Repo is dirty, cannot capture url and commit: /myrepo
```



### Logs

_No response_

Discussion:
CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan?pullRequest=15271) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan?pullRequest=15271) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan?pullRequest=15271) it.</sub>
Solviana: > It would be necessary to add a test that covers the need for this, so if someone sometime removes it, the test will fail.
> 
> There are a bunch of tests in `test_git.py` that you could use as a base, but let us know if you need help, we can even try to contribute the test if necessary.

I'll get familiar with your setup and I will create the tests, no prob!
memsharded: Hi @Solviana 

I am submitting a very related PR to fix a ``Git.is_dirty()`` bug, see https://github.com/conan-io/conan/pull/15289, you can see a unit test there, I hope it helps.

If you'd like to include this fix in 2.0.15, it will be most likely branched tomorrow, if you could manage to do the test, please let me know, and I'll try to include it.
Solviana: @memsharded 

I was afk for a while but now I updated the PR with some tests. Can you review this again?
RubenRBS: The new flags are 10 and 15 years old, respectively - no need for us to worry about that I think heh

Patch:
diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py
index 5f7e3fbe7..f80ca5882 100644
--- a/conan/tools/scm/git.py
+++ b/conan/tools/scm/git.py
@@ -103,7 +103,7 @@ class Git:
 
         :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"):


Test patch:
diff --git a/conans/test/functional/tools/scm/test_git.py b/conans/test/functional/tools/scm/test_git.py
index 73ed31cfd..632cc5ccc 100644
--- a/conans/test/functional/tools/scm/test_git.py
+++ b/conans/test/functional/tools/scm/test_git.py
@@ -179,6 +179,32 @@ class TestGitCaptureSCM:
             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: