2019-02-11 01:17:07 -08:00
|
|
|
# lethe README
|
|
|
|
|
2019-10-27 12:59:54 -07:00
|
|
|
`lethe` is a Python module for git-based snapshotting.
|
2019-02-11 01:17:07 -08:00
|
|
|
|
2019-10-27 12:59:54 -07:00
|
|
|
`lethe` is intended as a mechanism for creating commits outside
|
2019-02-11 01:17:07 -08:00
|
|
|
the standard git branching/tagging workflows. It is meant to enable
|
|
|
|
additional use-cases without disrupting the standard workflows.
|
|
|
|
Use cases include:
|
|
|
|
|
|
|
|
- Short-lived:
|
|
|
|
- On-disk **undo log**
|
2019-10-27 12:59:54 -07:00
|
|
|
- **Syncing work-in-progress** between computers before it's ready
|
2019-02-11 01:17:07 -08:00
|
|
|
- Long-lived:
|
|
|
|
- **lab notebook**: Recording the code / configuration state that resulted in a given output
|
2019-10-27 12:59:54 -07:00
|
|
|
- **incremental backup**: Space-efficient time-based backups of a codebase
|
2019-02-11 01:17:07 -08:00
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2019-10-27 12:59:54 -07:00
|
|
|
### Creating a commit from the command line
|
2019-02-11 01:17:07 -08:00
|
|
|
```bash
|
|
|
|
$ cd path/to/repo
|
|
|
|
$ lethe
|
|
|
|
122d058e375274a186c407f28602c3b14a2cab95
|
|
|
|
```
|
|
|
|
This effectively snapshots the current state of the repository (as would be seen by
|
2019-10-27 12:59:54 -07:00
|
|
|
`git add --all`) and creates a new commit (`122d058e375274a186c407f28602c3b14a2cab95`)
|
2019-02-11 01:17:07 -08:00
|
|
|
which points to it. The current branch and index are not changed.
|
|
|
|
|
|
|
|
### Flags:
|
2019-10-27 12:59:54 -07:00
|
|
|
- `-p my_parent_ref` is used to provide "parent" refs which become the parents of the created commit.
|
2019-02-11 01:17:07 -08:00
|
|
|
If a parent ref is a symbolic ref, *both* the provided ref and the ref it points to are used as parents.
|
2019-10-27 12:59:54 -07:00
|
|
|
If not present, defaults to `-p HEAD`.
|
|
|
|
- `-t ref/lethe/my_target_ref` is used to provide "target" refs which will be created/updated
|
2019-02-11 01:17:07 -08:00
|
|
|
to point to the created commit.
|
2019-10-27 12:59:54 -07:00
|
|
|
If not present, defaults to adding an entry of the form `-t refs/lethe/my_branch` for each
|
|
|
|
parent ref of the form `refs/heads/my_branch`, and `-t refs/lethe/my/refpath` for non-head
|
|
|
|
refs of the form `refs/my/refpath`. All provided parent refs *and* any dereferenced parent refs
|
2019-02-11 01:17:07 -08:00
|
|
|
are used to generate default target refs.
|
|
|
|
If any of the target refs already exist, the commits they point to become parents of the created commit.
|
2019-10-27 12:59:54 -07:00
|
|
|
- `-m "my message"` sets the commit message for the snapshot. By default, "snapshot <current datetime>" is used.
|
|
|
|
- `-r path/to/repo` can be provided to specify a repository outside of the current working directory.
|
2019-02-11 01:17:07 -08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ cd path/to/repo
|
|
|
|
$ git branch
|
|
|
|
* master
|
|
|
|
$ lethe
|
|
|
|
```
|
|
|
|
is equivalent to
|
|
|
|
```bash
|
|
|
|
lethe -r path/to/repo -p HEAD
|
|
|
|
```
|
|
|
|
or
|
|
|
|
```bash
|
|
|
|
lethe -r path/to/repo -p HEAD -p refs/heads/master -t refs/lethe/HEAD -t refs/lethe/master
|
|
|
|
```
|
|
|
|
|
|
|
|
### Creating a commit programmatically
|
|
|
|
```python
|
|
|
|
import lethe
|
|
|
|
REPO = '/path/to/repo'
|
|
|
|
|
|
|
|
commit_sha = lethe.snap(cwd=REPO)
|
|
|
|
tree_sha = lethe.get_tree(commit_sha, cwd=REPO)
|
|
|
|
|
|
|
|
print('Created new commit with hash ' + commit_sha + ' aka refs/lethe/HEAD')
|
|
|
|
print('Code (tree) state is ' + tree_sha)
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
Requirements:
|
|
|
|
* python 3 (written and tested with 3.6)
|
2019-10-27 12:59:54 -07:00
|
|
|
* git (accessible on the system `PATH`)
|
2019-02-11 01:17:07 -08:00
|
|
|
|
|
|
|
Install with pip:
|
|
|
|
```bash
|
2019-10-27 12:59:54 -07:00
|
|
|
pip3 install lethe
|
2019-02-11 01:17:07 -08:00
|
|
|
```
|