Package: kids.vcs
kids.vcsis a Python library providing GIT helpers. Would have
named itkids.gitif it didn’t messed everything with github.It’s part of ‘Kids’ (for Keep It Dead Simple) library.Featuresusingkids.vcs:You can manage and access your git repository, commits, logs, or git
config.CompatibilityThis code is python2 and python3 ready. It wasn’t tested on windows.InstallationYou don’t need to download the GIT version of the code askids.vcsis
available on the PyPI. So you should be able to run:pip install kids.vcsIf you have downloaded the GIT sources, then you could add install
the current version via traditional:python setup.py installAnd if you don’t have the GIT sources but would like to get the latest
master or branch from github, you could also:pip install git+https://github.com/0k/kids.vcsOr even select a specific revision (branch/tag/commit):pip install git+https://github.com/0k/kids.vcs@masterUsageLet’s play with a new git repository, let’s first create temporary
directory:>>> from __future__ import print_function

>>> import tempfile, os
>>> old_cwd = os.getcwd()
>>> tmpdir = tempfile.mkdtemp()
>>> os.chdir(tmpdir)Let’s now create a real git repository:>>> from kids.vcs import gitThis first command will create a new directory and launchgit initand
and will return the newGitReposobject:>>> r = git.GitRepos.create("repos",
...                         email="committer@example.com",
...                         name="The Committer")You might also want to only use an existing directory and launchgit initthen
use:>>> r = git.GitRepos.init("repos")Or, if wanting to use an already existing folder already initialised:>>> r = git.GitRepos("repos")By default, the current directory is used and the top-most git repository
that contains the current directory will be used as the master git repository.Avoid instantiating a non-existent git repository:>>> git.GitRepos("/")
Traceback (most recent call last):
...
OSError: Not a git repository ('/' or any of the parent directories).Git commands shortcutAside from all the helpers that will be exposed in the following section, aGitReposobject provides a handy.gitattribute to directly tap on
the git command line:>>> print(r.git.rev_parse(is_bare_repository=True))
falseA few things to note:the method name is the git command you want to launch_(underscores) are swapped for-.there are 2 different way to use the methods:provide one unique array of strings that will simply appended
on the command line.provide string positional arguments and keyword arguments:keyword arguments are options… :a double-dash will be added before the keyword if it is
composed of more than one chara single dash will be added before the keyword in cas it
a single character keyword._(underscores) are swapped for-in keyword nameand value is appended just after on the command line.positional arguments are appended AFTER all the options…the method return value is the space-stripped standard output of the
command sent.To illustrate this and the following points:>>> print(r.git.commit(
...     message='new: first commit',
...     author='Bob <bob@example.com>',
...     date='2000-01-01 10:00:00',
...     allow_empty=True))
[master (root-commit) ...] new: first commit
 Author: Bob <bob@example.com>
 Date: Sat Jan 1 10:00:00 2000 ...

>>> print(r.git.tag("0.0.1"))
>>> print(r.git.commit(
...     message='new: second commit',
...     author='Alice <alice@example.com>',
...     date='2000-01-02 11:00:00',
...     allow_empty=True))
[master ...] new: second commit
 Author: Alice <alice@example.com>
 Date: Sun Jan 2 11:00:00 2000 ...
>>> print(r.git.tag("0.0.2"))Access core informationsYou can get interesting information fron the git repository itself:>>> print(r.toplevel)
/.../repos

>>> r.bare
False

>>> print(r.gitdir)
/.../repos/.gitRead git configWe can access the config thanks to:>>> r.config
<...GitConfig...>

>>> print(r.config["core.filemode"])
trueYou can also instanciate directly theGitConfigclass:>>> from kids.vcs import git

>>> print(git.GitConfig("repos")["core.filemode"])
trueWithout any repository, it’s the current repository that should be
used, and if none, well it should answer as much as a normalgit configwould:>>> git.GitConfig()["core.filemode"]
Traceback (most recent call last):
...
KeyError: 'core.filemode'
>>> os.chdir("repos")
>>> print(git.GitConfig()["core.filemode"])
trueGit commit accessWe can access interesting information per commit:>>> r.commit("HEAD")
<GitCommit 'HEAD'>And several information are available:>>> print(r.commit("HEAD").author_name)
Alice
>>> print(r.commit("master").subject)
new: second commitYou can access to all of these:>>> print(", ".join(sorted(git.GIT_FORMAT_KEYS)))
author_date, author_date_timestamp, author_email, author_name, body,
committer_date_timestamp, committer_name, decorate_string,
parent_list_string, raw_body, sha1, sha1_short, subjectThere’s a convienience attributedatealso:>>> print(r.commit("0.0.2").date)
2000-01-02TagsYou can get the list of tags:>>> r.tags
[<GitCommit ...'0.0.1'>, <GitCommit ...'0.0.2'>]LogsYou can access all commits via:>>> list(r.log())
[<GitCommit ...>, <GitCommit ...>]and provide wich commit ancestry to include or to exclude (seegit log):>>> list(r.log(["HEAD", "^0.0.1", ]))
[<GitCommit ...>]ContributingAny suggestion or issue is welcome. Push request are very welcome,
please check out the guidelines.Push Request GuidelinesYou can send any code. I’ll look at it and will integrate it myself in
the code base and leave you as the author. This process can take time and
it’ll take less time if you follow the following guidelines:check your code with PEP8 or pylint. Try to stick to 80 columns wide.separate your commits per smallest concern.each commit should pass the tests (to allow easy bisect)each functionality/bugfix commit should contain the code, tests,
and doc.prior minor commit with typographic or code cosmetic changes are
very welcome. These should be tagged in their commit summary with!minor.the commit message should follow gitchangelog rules (check the git
log to get examples)if the commit fixes an issue or finished the implementation of a
feature, please mention it in the summary.If you have some questions about guidelines which is not answered here,
please check the currentgit log, you might find previous commit that
would show you how to deal with your issue.LicenseCopyright (c) 2019 Valentin Lab.Licensed under theBSD License.Changelog0.0.3 (2019-04-02)NewAddGitUrlas a conveniency to access parts of a remote git
repository url. [Valentin Lab]Addedls_remote(url),remote_url_reachable(url),query_remote_for_ref(url, ref)to work with remote repository.
[Valentin Lab]Provide a shortcut togitcommand line directly in module.
[Valentin Lab]FixPython3.7compatibility fix. [Valentin Lab]0.0.2 (2018-04-09)NewMajor update. [Valentin Lab]GitCommit: does not recognize magic identifierLASTanymore.GitCommit: added new attributes to access direct info of commitsha1_short,author_email,parent_list_string,decorate_stringGitCommit: added pythonic access to generic trailer values usingtrailer_LABELattributes. Supports multi-valued trailer values.GitCommit: specificauthors,author_namesspecial attributes
that leverageCo-Authored-Bytrailer value and commit author to
provide a full list of authors.GitCommit: newparentsattribute to get the GitCommit parent list.GitCommit: newtags_nameattribute to get the list of tags attributed
to current commit, along withtagsthat iterates through newGitTagobjects of the current commit, and.tag(label)method to instantiate
aGitTagof current commit thanks to its label.GitCommit: support of<(less-than) operator to map as close as possible
with order relation of commits given by command git log.GitCommit: support ofin(.__contains__(..)) operator to map with
ancestor relationship.newGitTag``objectthat represent annotated tags andnon-annotatedtags, check ``README.rstfor usage.GitRepos: new.create(..)classmethod to create a new git repository.GitRepos: new.init(..)classmethod to create a new git repository from
an existing repository.GitRepos: new.Tag(label)method to get a GitTag object from a given label.GitRepos: renamed.commit(..)method to.Commit(..). Old method still
kept for compatibility reason.GitRepos: renamed.config(..)method to.Config(..). Old method still
kept for compatibility reason.GitRepos: API CHANGE:.log(..)method is now closer togit logcommand
line usage, andincludes,excludes,include_mergearguments have
been removed. Please refer to documentation for more information.FixCatches bad repository when usingGitRepos.log(). [Valentin Lab]GitConfig()would fail if no arg. [Valentin Lab]0.0.1 (2015-02-05)First import. [Valentin Lab]