summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/git-preview
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2017-10-18 19:54:20 +0200
committerlassulus <lassulus@lassul.us>2017-10-18 19:54:20 +0200
commitd380d6060ea8ebe37cf392570c038ad95a4b98af (patch)
tree325815907e118c097e53e5d2768f45f9616bd50e /krebs/5pkgs/simple/git-preview
parent55f89e6ecae55e206ee6f0ac4e0edc116cdbba8e (diff)
parentdaca154ce3c75d232ed6c8ccc2375ac681b213ad (diff)
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'krebs/5pkgs/simple/git-preview')
-rw-r--r--krebs/5pkgs/simple/git-preview/default.nix25
1 files changed, 13 insertions, 12 deletions
diff --git a/krebs/5pkgs/simple/git-preview/default.nix b/krebs/5pkgs/simple/git-preview/default.nix
index f20f2a636..77826f34b 100644
--- a/krebs/5pkgs/simple/git-preview/default.nix
+++ b/krebs/5pkgs/simple/git-preview/default.nix
@@ -1,15 +1,16 @@
-{ coreutils, git, stdenv, writeDashBin }:
+{ coreutils, git, writeDashBin }:
writeDashBin "git-preview" ''
- PATH=${stdenv.lib.makeBinPath [
- coreutils
- git
- ]}''${PATH+:$PATH}
- hashes=$(git log --format=%h "..$1")
- end=$(echo "$hashes" | head -1)
- start=$(echo "$hashes" | tail -1)
- # exit if no diff was found
- test -z "$start" && exit 0
- shift
- git diff "$start^..$end" "$@"
+ set -efu
+ head_commit=$(${git}/bin/git log -1 --format=%H)
+ merge_commit=$1; shift
+ merge_message='Merge for git-preview'
+ preview_dir=$(${coreutils}/bin/mktemp --tmpdir -d git-preview.XXXXXXXX)
+ preview_name=$(${coreutils}/bin/basename "$preview_dir")
+ ${git}/bin/git worktree add --detach -f "$preview_dir" 2>/dev/null
+ ${git}/bin/git -C "$preview_dir" checkout -q "$head_commit"
+ ${git}/bin/git -C "$preview_dir" merge -qm "$merge_message" "$merge_commit"
+ ${git}/bin/git -C "$preview_dir" diff "$head_commit.." "$@"
+ ${coreutils}/bin/rm -fR "$preview_dir"
+ ${coreutils}/bin/rm -R .git/worktrees/"$preview_name"
''