From 576e94798ded05bb8eaf6e88c3fd1919eb14088d Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 29 May 2016 20:19:50 +0200 Subject: pkgs: Add new script git-detach It's a small helper tool which I specifically use for running NixOS tests (especially the installer ones) that require to be copied to the store. What git-detach does is creating a temporary working directory which only contains a trimmed-down (without untracked files and .git directory) version of the current Git repository. So in case of this is especially useful to keep down the closure size whenever the working dir is going to be exported to the store. Signed-off-by: aszlig --- pkgs/default.nix | 1 + pkgs/git-detach/default.nix | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 pkgs/git-detach/default.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index 674ae29d..074f1130 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -10,6 +10,7 @@ let axbo = callPackage ./axbo { }; beehive = callPackage ./beehive { }; blop = callPackage ./blop { }; + git-detach = callPackage ./git-detach { }; grandpa = callPackage ./grandpa { }; greybird-xfce-theme = callPackage ./greybird-xfce-theme { }; nixops = callPackage ./nixops { }; diff --git a/pkgs/git-detach/default.nix b/pkgs/git-detach/default.nix new file mode 100644 index 00000000..fb20843e --- /dev/null +++ b/pkgs/git-detach/default.nix @@ -0,0 +1,33 @@ +{ writeScriptBin, stdenv, git, coreutils, patch }: + +writeScriptBin "git-detach" '' + #!${stdenv.shell} + + if [ $# -le 0 -o "$1" = "--help" -o "$1" = "-h" ]; then + echo "Usage: $0 COMMAND [ARGS...]" >&2 + echo >&2 + echo "Run COMMAND in a clean Git working directory" >&2 + echo "without untracked files and .git directory." >&2 + exit 1 + fi + + diffToHead="$("${git}/bin/git" diff HEAD)" + + if tmpdir="$("${coreutils}/bin/mktemp" -d git-detach.XXXXXXXXXX)"; then + trap "rm -rf '${"\${tmpdir//\\'/\\'\\\\\\'\\'}"}'" EXIT + "${git}/bin/git" archive --format=tar HEAD | ( + set -e + basedir="$tmpdir/$("${coreutils}/bin/basename" "$(pwd)")" + mkdir "$basedir" + cd "$basedir" + tar x + if [ -n "$diffToHead" ]; then + echo "$diffToHead" | "${patch}/bin/patch" -s -p1 + fi + exec "$@" + ) + exit $? + else + echo "Unable to create temporary directory!" >&2 + fi +'' -- cgit 1.4.1