-
Notifications
You must be signed in to change notification settings - Fork 955
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
introducing modern conan.tool.scm.Git helper #10594
Merged
Merged
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ae66be8
introducing modern conan.tool.scm.Git helper
memsharded 1bfa516
skip Py2, change git config order
memsharded d811e17
wip
memsharded ccca294
wip
memsharded 04e356d
Merge branch 'develop' into feature/new_scm_git
memsharded 9c0e46b
wip
memsharded 6af4427
wip
memsharded eeb123b
let conandata_update create conandata.yml if not exist
memsharded db807ec
Merge branch 'fix/conandata_update_create' into feature/new_scm_git
memsharded d77c1a6
full SCM test
memsharded 679ec4b
adding monorepo case
memsharded 683700a
fix test
memsharded 9d3e456
fix test
memsharded 4a63607
Merge branch 'develop' into feature/new_scm_git
memsharded da035a3
fix tests
memsharded ea8bd95
fix test
memsharded 42a7a00
merge develop
memsharded e6ba52a
add subfolder test
memsharded a4aa3a9
Merge branch 'develop' into feature/new_scm_git
memsharded a092439
proposing base_source_folder, and folders.root
memsharded 658e7c3
Merge branch 'develop' into feature/base_source_folder
memsharded 29fb041
Merge branch 'develop' into feature/new_scm_git
memsharded ff7e5e5
Update conans/model/layout.py
memsharded b01610d
[feature] `ConfDefinition` and `Conf` enhancements. (#10537)
franramirez688 b5cd928
[PkgConfigDeps] Added new property `component_version` (#10633)
franramirez688 6209836
package_folder available when "conan install" consumer (#10655)
lasote 13e2a71
added a few conf checkers (#10656)
memsharded ad8af04
Use absolute paths in conanbuild.sh (#10653)
czoido 3543fcc
Cleanup tmpdirs (#10663)
lasote 64d5c1d
refactor toolchain (#10665)
lasote 604ba15
fix not finding the Premake executable (#10250)
Enhex b6971ba
review
memsharded 827b39a
Merge branch 'develop' into feature/base_source_folder
memsharded c6e4317
Merge branch 'develop' into feature/new_scm_git
memsharded 0aba37a
wip
memsharded 45741ba
Merge branch 'feature/base_source_folder' into feature/new_scm_git
memsharded 2cf53db
simplified tests
memsharded b710317
Merge branch 'develop' into feature/new_scm_git
memsharded cadb399
new branch test
memsharded 6dde3ca
review
memsharded 18491a6
fix test
memsharded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from conan.tools.scm.git import Git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import os | ||
|
||
from conan.tools.files import chdir | ||
from conans.errors import ConanException | ||
from conans.util.files import mkdir | ||
from conans.util.runners import check_output_runner | ||
|
||
|
||
class Git(object): | ||
def __init__(self, conanfile, folder="."): | ||
self._conanfile = conanfile | ||
self.folder = folder | ||
|
||
def _run(self, cmd): | ||
with chdir(self._conanfile, self.folder): | ||
return check_output_runner("git {}".format(cmd)).strip() | ||
|
||
def get_commit(self): | ||
try: | ||
# commit = self._run("rev-parse HEAD") For the whole repo | ||
# This rev-list knows to capture the last commit for the folder | ||
commit = self._run('rev-list HEAD -n 1 -- "{}"'.format(self.folder)) | ||
return commit | ||
except Exception as e: | ||
raise ConanException("Unable to get git commit in '%s': %s" % (self.folder, str(e))) | ||
|
||
def get_remote_url(self, remote="origin"): | ||
remotes = self._run("remote -v") | ||
for r in remotes.splitlines(): | ||
name, url = r.split(maxsplit=1) | ||
if name == remote: | ||
url, _ = url.rsplit(None, 1) | ||
if os.path.exists(url): # Windows local directory | ||
url = url.replace("\\", "/") | ||
return url | ||
|
||
def commit_in_remote(self, commit, remote="origin"): | ||
if not remote: | ||
return False | ||
try: | ||
branches = self._run("branch -r --contains {}".format(commit)) | ||
return "{}/".format(remote) in branches | ||
except Exception as e: | ||
raise ConanException("Unable to check remote commit in '%s': %s" % (self.folder, str(e))) | ||
|
||
def is_dirty(self): | ||
status = self._run("status -s").strip() | ||
return bool(status) | ||
|
||
def get_url_and_commit(self, remote="origin"): | ||
dirty = self.is_dirty() | ||
if dirty: | ||
raise ConanException("Repo is dirty, cannot capture url and commit: " | ||
"{}".format(self.folder)) | ||
commit = self.get_commit() | ||
url = self.get_remote_url(remote=remote) | ||
in_remote = self.commit_in_remote(commit, remote=remote) | ||
if in_remote: | ||
return url, commit | ||
# TODO: Once we know how to pass [conf] to export, enable this | ||
# conf_name = "tools.scm:local" | ||
# allow_local = self._conanfile.conf[conf_name] | ||
# if not allow_local: | ||
# raise ConanException("Current commit {} doesn't exist in remote {}\n" | ||
# "use '-c {}=1' to allow it".format(commit, remote, conf_name)) | ||
|
||
self._conanfile.output.warn("Current commit {} doesn't exist in remote {}\n" | ||
"This revision will not be buildable in other " | ||
"computer".format(commit, remote)) | ||
return self.get_repo_root(), commit | ||
|
||
def get_repo_root(self): | ||
folder = self._run("rev-parse --show-toplevel") | ||
return folder.replace("\\", "/") | ||
|
||
def clone(self, url, target=""): | ||
if os.path.exists(url): | ||
url = url.replace("\\", "/") # Windows local directory | ||
mkdir(self.folder) | ||
self._conanfile.output.info("Cloning git repo") | ||
self._run('clone "{}" {}'.format(url, target)) | ||
|
||
def checkout(self, commit): | ||
self._conanfile.output.info("Checkout: {}".format(commit)) | ||
self._run('checkout {}'.format(commit)) |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name to be improved. Suggestions welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a generic
move_folder_contents(dst_folder, folder, clean_first=True)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe we can split the operation in two, one for removing all folders but the one we want and other for moving the folder... or
move_folder_contents(dst_folder, folder, clean_first=True)
is more explicit, I'm ok with that too, maybeclean_other
instead ofclean_first
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am annotating it to NOT document, so we can think about file methods in a more broad perspective, this PR is focused on the Git integration for sources, this is a very minor detail, just to prove it is possible to implement the mono-repo approach