1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-26 21:19:47 +01:00

add shallow option to git source type

This commit is contained in:
Enno Lohmeier 2020-07-02 09:27:55 +02:00
parent 3e731035ed
commit 54eb1c89cf
3 changed files with 23 additions and 3 deletions

View file

@ -242,6 +242,10 @@ Supported attributes:
* `clean.exclude` - * `clean.exclude` -
List of patterns that should be excluded from Git cleaning. List of patterns that should be excluded from Git cleaning.
* `shallow` (optional)
boolean that controls whether only the requested commit ref. should be fetched
instead of the whole history, to save disk space and bandwith. Defaults to `false`.
### `pass` ### `pass`

View file

@ -140,6 +140,10 @@
url = lib.mkOption { url = lib.mkOption {
type = lib.types.str; # TODO lib.types.git.url type = lib.types.str; # TODO lib.types.git.url
}; };
shallow = lib.mkOption {
default = false;
type = lib.types.bool;
};
}; };
}; };
pass = lib.types.submodule { pass = lib.types.submodule {

View file

@ -53,7 +53,11 @@ let
pop.git = target: source: runShell target /* sh */ '' pop.git = target: source: runShell target /* sh */ ''
set -efu set -efu
if ! test -e ${quote target.path}; then if ! test -e ${quote target.path}; then
${if source.shallow then /* sh */ ''
git init ${quote target.path}
'' else /* sh */ ''
git clone --recurse-submodules ${quote source.url} ${quote target.path} git clone --recurse-submodules ${quote source.url} ${quote target.path}
''}
fi fi
cd ${quote target.path} cd ${quote target.path}
if ! url=$(git config remote.origin.url); then if ! url=$(git config remote.origin.url); then
@ -67,10 +71,18 @@ let
if ! test "$(git log --format=%H -1)" = "$hash"; then if ! test "$(git log --format=%H -1)" = "$hash"; then
${if source.fetchAlways then /* sh */ '' ${if source.fetchAlways then /* sh */ ''
${if source.shallow then /* sh */ ''
git fetch --depth=1 origin "$hash"
'' else /* sh */ ''
git fetch origin git fetch origin
''}
'' else /* sh */ '' '' else /* sh */ ''
if ! git log -1 "$hash" >/dev/null 2>&1; then if ! git log -1 "$hash" >/dev/null 2>&1; then
${if source.shallow then /* sh */ ''
git fetch --depth=1 origin "$hash"
'' else /* sh */ ''
git fetch origin git fetch origin
''}
fi fi
''} ''}
git reset --hard "$hash" >&2 git reset --hard "$hash" >&2