summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/git-preview/default.nix
blob: f0ed4dfd678e164e9bbb7719ddc88080aa378b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{ coreutils, git, writeDashBin }:

writeDashBin "git-preview" ''
  set -efu
  # Checked here: merge-tree fails with exit status 1 for a name it can't
  # resolve, too, which would pass for a conflict below.
  merge_commit=$(${git}/bin/git rev-parse --verify "$1^{commit}"); shift
  # Merges in the object store, without a worktree: exit status 1 means
  # conflicts, which the tree then holds as conflict markers.
  output=$(${git}/bin/git merge-tree --write-tree HEAD "$merge_commit") || {
    status=$?
    test "$status" = 1 || exit "$status"
  }
  tree=$(printf '%s\n' "$output" | ${coreutils}/bin/head -n 1)
  ${git}/bin/git diff HEAD "$tree" "$@"
''