Repository: conan-io/conan
Pull request: Add a repository parameter to coordinates_to_conandata().
Changelog: Feature: Forward repository parameter (with same default) from `coordinates_to_conandata()` to `get_url_and_commit()`.
Docs: Omit

fixes #17698 

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop2/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [ ] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one.


Problem statement:
[feature] Git.coordinates_to_conandata() is missing the repository argument.
### What is your suggestion?

As discussed in previous issues, a `repository` argument has been added to both  `Git.get_commit()` and `Git.get_url_and_commit()`.
It looks like an oversight that it is not present on `Git.coordinates_to_conandata()`.

### Have you read the CONTRIBUTING guide?

- [x] I've read the CONTRIBUTING guide

Hints from issue discussion:
Hi @Adnn 

Thanks for the suggestion.

This looks like a valid case, and it looks pretty trivial to implement.
Do you think there is any downside or possible risk? Anything that should be taken into account if storing the repo commit instead of the folder one? Should anything change in the stored data in the ``conandata.yml``? I think not, but just in case.
Hi @memsharded , and thank you for your answer.

As far as I understand the situation, `repository=True` | `repository=False` are really orthgonal use-cases (1st for hosting a single conanfile in a subfolder of a repo, second for hosting distinct conanfiles in a single repo).
I suppose `coordinates_to_conandata()` is implemented under the hood in term of `get_url_and_commit()`, so I think it was a simple oversight, and forwarding the parameter (with the same default value of `False`) should not cause anyone any surprises.
I will actually try to implement this trivial forward, pay a tiny bit of my due.

Commit message: Add a repository parameter to coordinates_to_conandata().

Patch to review:
diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py
index 6e0ad9e27c3..b09174bd473 100644
--- a/conan/tools/scm/git.py
+++ b/conan/tools/scm/git.py
@@ -260,15 +260,18 @@ def included_files(self):
         files = files.splitlines()
         return files
 
-    def coordinates_to_conandata(self):
+    def coordinates_to_conandata(self, repository=False):
         """
         Capture the "url" and "commit" from the Git repo, calling ``get_url_and_commit()``, and then
         store those in the ``conandata.yml`` under the "scm" key. This information can be
         used later to clone and checkout the exact source point that was used to create this
         package, and can be useful even if the recipe uses ``exports_sources`` as mechanism to
         embed the sources.
+
+        :param repository: By default gets the commit of the defined folder, use repository=True to get
+                     the commit of the repository instead.
         """
-        scm_url, scm_commit = self.get_url_and_commit()
+        scm_url, scm_commit = self.get_url_and_commit(repository)
         update_conandata(self._conanfile, {"scm": {"commit": scm_commit, "url": scm_url}})
 
     def checkout_from_conandata_coordinates(self):


Code review comments:
diff_hunk: @@ -260,15 +260,18 @@ def included_files(self):
         files = files.splitlines()
         return files
 
-    def coordinates_to_conandata(self):
+    def coordinates_to_conandata(self, repository=False):
         """
         Capture the "url" and "commit" from the Git repo, calling ``get_url_and_commit()``, and then
         store those in the ``conandata.yml`` under the "scm" key. This information can be
         used later to clone and checkout the exact source point that was used to create this
         package, and can be useful even if the recipe uses ``exports_sources`` as mechanism to
         embed the sources.
+
+        :param repository: By default gets the commit of the defined folder, use repository=True to get
+                     the commit of the repository instead.
         """
-        scm_url, scm_commit = self.get_url_and_commit()
+        scm_url, scm_commit = self.get_url_and_commit(repository)
path: conan/tools/scm/git.py
text: @user1:
```suggestion
        scm_url, scm_commit = self.get_url_and_commit(repository=repository)
```
The first argument to ``get_url_and_commit()`` is the "origin" remote