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

scm folders #3271

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions reference/tools/scm/git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
Git
===

The ``Git`` helper is a thin wrapper over the ``git`` command. It can be used for different purposes:
- Obtaining the current tag in the ``set_version()`` method to assign it to ``self.version``
- Clone sources in third-party or open source package recipes in the ``source()`` method (in general, doing a ``download()`` or ``get()`` to fetch release tarballs will be preferred)
- Capturing the "scm" coordinates (url, commit) of your own package sources in the ``export()`` method, to be able to reproduce a build from source later, retrieving the code in the ``source()`` method. See the :ref:`example of git-scm capture<examples_tools_scm_git_capture>`.

The ``Git()`` constructor receives the current folder as argument, but that can be changed if necessary, for example, to clone the sources of some repo in ``source()``:


.. code-block:: python

def source(self):
git = Git(self) # by default, the current folder "."
git.clone(url="<repourl>", target="target") # git clone url target
# we need to cd directory for next command "checkout" to work
git.folder = "target" # cd target
git.checkout(commit="<commit>") # git checkout commit


An alternative, equivalent approach would be:

.. code-block:: python

def source(self):
git = Git(self, "target")
# Cloning in current dir, not a children folder
git.clone(url="<repourl>", target=".")
git.checkout(commit="<commit>")



.. currentmodule:: conan.tools.scm.git

.. autoclass:: Git
Expand Down