diff options
| author | tv <tv@krebsco.de> | 2026-12-02 15:29:06 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-02 16:39:05 +0100 |
| commit | e48a64c9a2922074ed7f5d355a88f1daf3a32362 (patch) | |
| tree | 379cb2d128324bf41f8f961c5da63eedb26affd3 /pkgs/simple | |
| parent | 88153380de45a35831e43f9cbc836b7bb357c490 (diff) | |
git-preview: merge with git merge-tree
The merge happens in the object store, without a worktree, a checkout or
a commit. That fixes a conflict stopping the script before it removed
its worktree, and the removal of .git/worktrees/NAME failing outside the
repository's top directory and in a linked worktree. A conflict now
shows in the diff, as conflict markers. merge-tree knows only git's
default strategy, so GIT_PREVIEW_MERGE_STRATEGY goes. The commit is
checked first, since merge-tree exits with 1, as for a conflict, for a
name it can't resolve.
Diffstat (limited to 'pkgs/simple')
| -rw-r--r-- | pkgs/simple/git-preview/default.nix | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/pkgs/simple/git-preview/default.nix b/pkgs/simple/git-preview/default.nix index da152507..f0ed4dfd 100644 --- a/pkgs/simple/git-preview/default.nix +++ b/pkgs/simple/git-preview/default.nix @@ -2,19 +2,15 @@ writeDashBin "git-preview" '' 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 \ - ''${GIT_PREVIEW_MERGE_STRATEGY+-s "$GIT_PREVIEW_MERGE_STRATEGY"} \ - -m "$merge_message" \ - -q \ - "$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" + # 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" "$@" '' |
