|
| 1 | +# Gitfile |
| 2 | + |
| 3 | +Gitfile is a MIT-Licensed Bash-script written in less than 100 lines to manage git repositores. |
| 4 | + |
| 5 | +Originally written as a replacement for terraform module managers like https://github.com/coretech/terrafile and https://github.com/devopsmakers/xterrafile |
| 6 | + |
| 7 | +Main reasons for the rewrite were: |
| 8 | + - both written in Go with dependencies for a job that can be done in bash in less than 100 lines |
| 9 | + - both always delete and re-clone the repository on execution |
| 10 | + - both always delete the path recursively (they seriously delete your working directory if it's part of the path) which makes it impossible for directory structures like: |
| 11 | + ```shell script |
| 12 | + workspace |
| 13 | + ├── moduleA |
| 14 | + │ ├── main.tf |
| 15 | + ├── moduleB |
| 16 | + │ ├── main.tf |
| 17 | + | ├── moduleA.tf |
| 18 | + ├── moduleC |
| 19 | + │ ├── main.tf |
| 20 | + │ ├── moduleA.tf |
| 21 | + │ ├── moduleB.tf |
| 22 | + ``` |
| 23 | + |
| 24 | +`Gitfile` ended up beeing a more general approach that enables git management in general |
| 25 | + |
| 26 | + |
| 27 | +## Features |
| 28 | + - doesn't delete your directories (looking at you `terrafile` tools -.-*) |
| 29 | + - clones repository only if it hasn't been cloned already |
| 30 | + - incremental changes are retrieved with fetch/checkout/pull |
| 31 | + - fetch/checkout/pull are only executed if there are no changes in the local repository |
| 32 | + - updates remote ULR if it changes (i.e. repo moved from github to self hosted domain) |
| 33 | + |
| 34 | +## Usage in automation |
| 35 | + |
| 36 | +In most cases you should be able to use the gitfile locally and in automation in exactly the same way. |
| 37 | +Nonetheless there are some use cases where you might prefer to Download your repository in automation using HTTPS instead of SSH or vice versa. |
| 38 | +Simply re-configure git in your pipeline to switch from http cloning to ssh cloning: |
| 39 | +```shell script |
| 40 | +git config --global url.ssh:// [email protected]/.insteadOf https://github.com/ |
| 41 | +``` |
| 42 | + |
| 43 | +## Install |
| 44 | + |
| 45 | +```shell script |
| 46 | +git clone https://github.com/Bobonium/gitfile.git |
| 47 | +cd gitfile |
| 48 | +make install |
| 49 | +``` |
| 50 | + |
| 51 | +or alternatively: |
| 52 | +```shell script |
| 53 | +curl -L https://raw.githubusercontent.com/Bobonium/gitfile/master/gitfile.sh > /usr/local/bin/gitfile |
| 54 | +``` |
| 55 | + |
| 56 | +#### dependencies: |
| 57 | + - git |
| 58 | + - openssh-client |
| 59 | + - make (for test/install) |
| 60 | + |
| 61 | + |
| 62 | +## Use |
| 63 | + |
| 64 | +#### Command overview |
| 65 | + |
| 66 | +```shell script |
| 67 | +#quick-start |
| 68 | +cd ~/workspace/github/Bobonium/gitfile/ |
| 69 | +gitfile |
| 70 | +``` |
| 71 | + |
| 72 | +```shell script |
| 73 | +#print help text |
| 74 | +gitfile -h #--help |
| 75 | +#path/filename to parse as gitfile (default: ./.gitfile) |
| 76 | +gitfile -f /path/to/gitfile #--gitfile -> |
| 77 | +#path to store repos without explicit `path` (default: ./) |
| 78 | +gitfile -p /default/clone/path #--default-clone-path |
| 79 | +``` |
| 80 | + |
| 81 | +#### .gitfile format |
| 82 | + |
| 83 | +This is only a YAML-like format! gitfile does not use a full blown yaml parser, but instead only implemented the minimal requirements through some shell commands. |
| 84 | +Feel free to create an Issue/Pull request if you find a problem with the parsing (or anything else of course). |
| 85 | + |
| 86 | +```yaml |
| 87 | +#required: repo will be cloned into dir with this name |
| 88 | +gitfile: |
| 89 | + #required: clone URL (can be either http(s) or ssh) |
| 90 | + source: "https://github.com/Bobonium/gitfile.git" |
| 91 | + #optional: path to clone the repository into (default taken from gitfile command) |
| 92 | + #relative path values are always relative to the path of the .gitfile |
| 93 | + path: ~/workspace/github/Bobonium/ |
| 94 | + #optional: version to checkout (defaults to master) |
| 95 | + #tags, branch names and commit hases are all valid values |
| 96 | + #if you can run `git checkout $VERSION` it's valid |
| 97 | + version: master |
| 98 | +``` |
| 99 | +
|
| 100 | +#### Release Cycle: |
| 101 | +
|
| 102 | +Master branch will always be the current release; if it's good enough to merge, it's good enough to be released |
0 commit comments