From 72ceb16f5fe9bf8b05eeaa2bf89307abf5efa0e0 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 1 Jul 2025 14:30:38 +0200 Subject: [PATCH 1/3] Add git automatic range diff Co-authored-by: Felix Buehler --- bin/git-ard.sh | 23 +++++++++++++++++++++++ install.conf.yaml | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 bin/git-ard.sh diff --git a/bin/git-ard.sh b/bin/git-ard.sh new file mode 100755 index 0000000..a1d5311 --- /dev/null +++ b/bin/git-ard.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Git automatic range diff + +# Enforce being in a git repository +git rev-parse --is-inside-work-tree >/dev/null || exit $? + +# We actually should check out the head branch via `git remote show ${REMOTE}`, +# but this requires active connection and active 2FA verification. Tedious to +# have multiple calls for this +if git rev-parse --verify main &>/dev/null; then + MAIN_BRANCH=main +else + MAIN_BRANCH=master +fi + +CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" +GIT_REMOTE=origin + +# Show the next command +set -x + +git range-diff "${GIT_REMOTE}/${MAIN_BRANCH}..${GIT_REMOTE}/${CURRENT_BRANCH}" "${MAIN_BRANCH}..${CURRENT_BRANCH}" diff --git a/install.conf.yaml b/install.conf.yaml index 1aa60f5..cf302c1 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -76,6 +76,7 @@ - link: ~/.local/bin/host-is-on: bin/host-is-on.sh ~/.local/bin/git-authors: bin/git-authors.sh + ~/.local/bin/git-ard: bin/git-ard.sh ~/.local/bin/clean: bin/clean.sh # systemd @@ -88,4 +89,3 @@ - link: ~/.local/bin/diff-so-fancy: git/diff-so-fancy/diff-so-fancy - From ad24ebe4a21ba3c1fb74bd364550a497a7f89542 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 31 Jul 2025 23:48:39 +0200 Subject: [PATCH 2/3] Enforce git commands being run inside git folder --- bin/git-authors.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/git-authors.sh b/bin/git-authors.sh index 3383558..709dacb 100755 --- a/bin/git-authors.sh +++ b/bin/git-authors.sh @@ -1,5 +1,8 @@ #!/bin/sh +# Enforce being in a git repository +git rev-parse --is-inside-work-tree >/dev/null || exit $? + # save as i.e.: git-authors and set the executable flag git ls-tree -r -z --name-only HEAD -- "${1}" \ | xargs -0 -n1 git blame --line-porcelain HEAD \ @@ -7,4 +10,3 @@ git ls-tree -r -z --name-only HEAD -- "${1}" \ | sort \ | uniq -c \ | sort -nr - From 808243babc2fdb6a51202a1b152eadf2c1907beb Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 25 Jul 2025 11:25:24 +0200 Subject: [PATCH 3/3] Add git-rewrite-commits --- bin/git-rewrite-commits.sh | 32 ++++++++++++++++++++++++++++++++ install.conf.yaml | 1 + 2 files changed, 33 insertions(+) create mode 100755 bin/git-rewrite-commits.sh diff --git a/bin/git-rewrite-commits.sh b/bin/git-rewrite-commits.sh new file mode 100755 index 0000000..217aa60 --- /dev/null +++ b/bin/git-rewrite-commits.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Automatically start a rebase for all commits between HEAD and the main +# branch without integrating new commits from the main branch +# +# Technically it's a git rebase without rebasing any commits. + +# Enforce being in a git repository +git rev-parse --is-inside-work-tree >/dev/null || exit $? + +# We actually should check out the head branch via `git remote show ${REMOTE}`, +# but this requires active connection and active 2FA verification. Tedious to +# have multiple calls for this +if git rev-parse --verify main &>/dev/null; then + MAIN_BRANCH=main +else + MAIN_BRANCH=master +fi + +CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" + +if [ "${CURRENT_BRANCH}" = "${MAIN_BRANCH}" ]; then + echo "Cannot rebase commits from '${CURRENT_BRANCH}' (HEAD) onto '${MAIN_BRANCH}'" >&2 + exit 1 +fi + +MERGE_BASE="$(git merge-base "${MAIN_BRANCH}" HEAD)" + +# Show the next command +set -x + +git rebase --interactive "${MERGE_BASE}" diff --git a/install.conf.yaml b/install.conf.yaml index cf302c1..6a77719 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -77,6 +77,7 @@ ~/.local/bin/host-is-on: bin/host-is-on.sh ~/.local/bin/git-authors: bin/git-authors.sh ~/.local/bin/git-ard: bin/git-ard.sh + ~/.local/bin/git-rewrite-commits: bin/git-rewrite-commits.sh ~/.local/bin/clean: bin/clean.sh # systemd