forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-pre-push-diff-base.sh
More file actions
executable file
·36 lines (31 loc) · 1.3 KB
/
Copy pathtest-pre-push-diff-base.sh
File metadata and controls
executable file
·36 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -euo pipefail
# Git hooks export their own repository environment. This fixture creates a
# separate temporary repository, so it must not inherit that hook context.
unset GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
HELPER="$ROOT/scripts/pre-push-diff-base"
TMPDIR="$(mktemp -d)"
cleanup() { rm -rf "$TMPDIR"; }
trap cleanup EXIT
git -C "$TMPDIR" init -q
git -C "$TMPDIR" config user.email test@example.com
git -C "$TMPDIR" config user.name test
printf 'base\n' >"$TMPDIR/base.txt"
git -C "$TMPDIR" add base.txt
git -C "$TMPDIR" commit -qm base
git -C "$TMPDIR" branch -M main
printf 'main\n' >"$TMPDIR/main.txt"
git -C "$TMPDIR" add main.txt
git -C "$TMPDIR" commit -qm main
git -C "$TMPDIR" branch feature HEAD~1
git -C "$TMPDIR" switch -q feature
printf 'desktop\n' >"$TMPDIR/desktop.txt"
git -C "$TMPDIR" add desktop.txt
git -C "$TMPDIR" commit -qm desktop
git -C "$TMPDIR" merge -q --no-edit main
base="$(cd "$TMPDIR" && "$HELPER" main HEAD)"
selected="$(git -C "$TMPDIR" diff --name-only "$base" HEAD)"
test "$selected" = "desktop.txt"
test "$(cd "$TMPDIR" && "$HELPER" "$(git rev-parse main)" "$(git rev-parse HEAD)")" = "$base"
echo "pre-push final-PR-diff selection tests passed"