Metadata-Version: 2.4
Name: fastgit
Version: 0.1.2
Summary: Use git from python, fast
Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
License: Apache-2.0
Project-URL: Repository, https://github.com/AnswerDotAI/fastgit
Project-URL: Documentation, https://AnswerDotAI.github.io/fastgit
Keywords: nbdev,jupyter,notebook,python
Classifier: Natural Language :: English
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastcore>=1.12.27
Dynamic: license-file

# fastgit


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

`fastgit` is a thin Python wrapper for the `git` CLI: one [`Git`](https://AnswerDotAI.github.io/fastgit/core.html#git) object whose attribute calls run git commands, so if you know git, you already know fastgit. There is no reimplementation of git internals and no object model to learn – commands return git’s own output as (subclassed) `str`s.

It is designed for interactive use and automation alike: errors print tersely by default (like git itself) or raise on request, exit codes that mean “no” rather than “failed” are returned normally, and passing `sync=False` gives an async client for servers and concurrent code.

## Usage

### Installation

Install latest from [pypi](https://pypi.org/project/fastgit/)

``` sh
$ pip install fastgit
```

### How to use

Create a [`Git`](https://AnswerDotAI.github.io/fastgit/core.html#git) for any directory; every command runs with that directory as its working tree. Method names map to git subcommands, and results come back as stripped strings:

``` python
import shutil, tempfile
```

``` python
td = tempfile.mkdtemp()
g = Git(td)
g.init(b='main')
```

    'Initialized empty Git repository in /private/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/tmp8zyj76q7/.git/'

``` python
(g.d/'.gitignore').mk_write('*.bak')
g.add('.gitignore')
g.commit(m='add .gitignore')
```

    '[main (root-commit) 5113ce1] add .gitignore\n 1 file changed, 1 insertion(+)\n create mode 100644 .gitignore'

Keyword arguments become options: single-letter names are short options (`n=1` → `-n 1`), longer names long options with underscores turned into dashes, and `True` passes the bare flag:

``` python
g.log(n=1, oneline=True)
```

    '5113ce1 add .gitignore'

You can also pass path arguments after `--` using the `__` parameter:

``` python
g.log('--oneline', __=['.gitignore'])
```

    '5113ce1 add .gitignore'

Frequent queries are properties:

``` python
g.current_branch, g.commits
```

    ('main', ['5113ce1 add .gitignore'])

A failed command prints git’s message and returns `None`; pass `raise_exc=True` (per call or at init) to raise instead. Where git uses exit 1 to mean “no” rather than “error” – like `grep` finding nothing – the output is returned as usual, with the code on `.returncode`:

``` python
res = g.grep('missing')
res.returncode
```

    1

Pass `sync=False` for an async client: the same commands and properties, each returning an awaitable, so a server never blocks its event loop on git:

``` python
ag = Git(td, sync=False)
await ag.last_commit
```

    'add .gitignore'
