diff --git a/hm/git/default.nix b/hm/git/default.nix index 0799152..36b8acf 100644 --- a/hm/git/default.nix +++ b/hm/git/default.nix @@ -3,17 +3,23 @@ config = lib.mkIf config.programs.git.enable { home.packages = [ (pkgs.writeShellApplication { - name = "git-sync-init"; + name = "git-sync"; text = (lib.strings.concatLines - (map (r: ''[ -d "${r.path}" ] || ${pkgs.git}/bin/git clone "${r.uri}" "${r.path}"'') - (lib.attrsets.attrValues config.services.git-sync.repositories) - ) - ); - }) - (pkgs.writeShellApplication { - name = "git-sync-pull"; - text = (lib.strings.concatLines - (map (r: ''(cd "${r.path}"; echo "$PWD"; ${pkgs.git}/bin/git pull || true)'') + (map + (r: '' + echo "===== ${r.path}" + if [ ! -d "${r.path}" ] + then + ${pkgs.git}/bin/git clone "${r.uri}" "${r.path}" + else + ( + cd "${r.path}" + ${pkgs.git}/bin/git diff --quiet || echo "Repository is dirty!" + ${pkgs.git}/bin/git pull || true + ${pkgs.git}/bin/git push || true + ) + fi + '') (lib.attrsets.attrValues config.services.git-sync.repositories) ) );