From efaf7e9a8804c9f376bacf9fb64ecdb4dc108168 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 11 Oct 2017 15:23:04 +0200 Subject: git-sync in /nix/store --- ymir.nix | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ymir.nix b/ymir.nix index 2d6fac63..b1adc5d4 100644 --- a/ymir.nix +++ b/ymir.nix @@ -891,7 +891,28 @@ in rec { [directory-sync] directory=/var/lib/infinoted/dirsync interval=5 - hook=/var/lib/infinoted/git-sync.sh + hook=${pkgs.writeScript "git-sync.sh" '' + #!${pkgs.zsh}/bin/zsh + + repository=$(git -C ${2:h} rev-parse --show-toplevel) + [[ $? -eq 0 ]] || exit 0 + + git() { + $(whence -cp git) -C ${repository} ${@} + } + + typeset -a changeSet + changeSet=() + git diff -z --name-only | \ + while IFS= read -r -d $'\0' change; do changeSet=(${changeSet} ${change}); done + + [[ ${changeSet[(i)$(realpath ${2} --relative-to=${repository})]} -le ${#changeSet} ]] || exit 0 + + commitMessage=$(printf "%s modified via infinoted" $(realpath ${2} --relative-to=${repository})) + git add ${2} + git commit -m ${commitMessage} --no-edit ${2} + git push + ''} ''; }; -- cgit v1.2.3