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

Add relative path support to Git SCM tool #11407

Merged
merged 3 commits into from Jun 12, 2022

Conversation

nmasseyKM
Copy link
Contributor

@nmasseyKM nmasseyKM commented Jun 6, 2022

Changelog: Feature: Add relative path support to Git SCM tool.
Docs: omit

Closes: #11408

When trying to setup Conan packaging with the target source in a submodule relative to the recipe, I was receiving
empty commit ids. Upon further investigation, it seems that the current assumption is that the folder path to Git()
will be absolute. A minor adjustment allows relative paths to be used as well: since the git command always chdirs to the
target git folder, we can perform the rev-parse relative to the current directory and receive the expected behavior.

  • Test cases have been added.
  • Documentation does not seem to warrant updates since this behavior is implied by the currently document default value for folder

Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.

@nmasseyKM nmasseyKM changed the title Git scm Add relative path support to Git SCM tool Jun 6, 2022
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for contributing to Conan.
Please have a look to the comments, and to the failing tests in CI: https://ci.conan.io/blue/organizations/jenkins/ConanTestSuite/detail/PR-11407/2/pipeline

@@ -22,7 +22,7 @@ def get_commit(self):
# --full-history is needed to not avoid wrong commits:
# https://github.com/conan-io/conan/issues/10971
# https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt-Defaultmode
commit = self._run('rev-list HEAD -n 1 --full-history -- "{}"'.format(self.folder))
commit = self._run('rev-list HEAD -n 1 --full-history -- "."')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this change will not guarantee that this is run in the specified self.folder, but in the cwd, which is not guarantee that it will be self.folder, if users specify a different value in the constructor, which they can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of _run above executes with chdir(self.folder)
The double use of self.folder means it ends up trying to resolve a relative path relative to the folder itself, and usually fails to find any commits touching that subtree.

Given the other uses of _run, its behavior seems correct and the adjustment to get_commit seemed more appropriate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, you are right, I missed that part. Looks good to me then.

conans/test/unittests/tools/scm/test_git_get_commit.py Outdated Show resolved Hide resolved
@nmasseyKM nmasseyKM changed the title Add relative path support to Git SCM tool draft: Add relative path support to Git SCM tool Jun 7, 2022
@nmasseyKM nmasseyKM marked this pull request as draft June 7, 2022 11:37
@nmasseyKM nmasseyKM changed the title draft: Add relative path support to Git SCM tool Add relative path support to Git SCM tool Jun 7, 2022
@nmasseyKM nmasseyKM force-pushed the git-scm branch 2 times, most recently from 269b95c to 9cfb364 Compare June 7, 2022 12:41
@@ -22,7 +22,7 @@ def get_commit(self):
# --full-history is needed to not avoid wrong commits:
# https://github.com/conan-io/conan/issues/10971
# https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt-Defaultmode
commit = self._run('rev-list HEAD -n 1 --full-history -- "{}"'.format(self.folder))
commit = self._run('rev-list HEAD -n 1 --full-history -- "."')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, you are right, I missed that part. Looks good to me then.

@memsharded memsharded added this to the 1.50 milestone Jun 7, 2022
@nmasseyKM nmasseyKM force-pushed the git-scm branch 2 times, most recently from 26e846f to 5ad70e5 Compare June 7, 2022 13:17
@nmasseyKM nmasseyKM marked this pull request as ready for review June 7, 2022 14:37
@memsharded memsharded merged commit cc30ecc into conan-io:develop Jun 12, 2022
@nmasseyKM nmasseyKM deleted the git-scm branch June 28, 2022 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Add relative path support to Git SCM tool
2 participants