From 21ab6af1d67153ba8df740c151b8283b037a44af Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 7 Nov 2021 13:35:54 +0200
Subject: [PATCH] Some git scripts cleanup.

Mainly about the default branch, fetching and rebasing on it.

- A nicer default-branch alias (without a shell).
- Address if running git-master on the default branch.
- Make git-master a script since it became too complex.
- Address if running git-remaster on the default branch.
- Make git-remaster a script sine it became too complex.
- Remove git-rerebase (I should just use git pull --rebase).
- Change git-ff to use a non-hardcoded default branch.
---
 .config/git/config         |  7 ++-----
 Documents/bin/git-master   | 17 +++++++++++++++++
 Documents/bin/git-remaster | 17 +++++++++++++++++
 3 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100755 Documents/bin/git-master
 create mode 100755 Documents/bin/git-remaster

diff --git a/.config/git/config b/.config/git/config
index 3c9412f..388cb13 100644
--- a/.config/git/config
+++ b/.config/git/config
@@ -9,15 +9,14 @@
     cdiff = diff --cached
     cleaan = clean -dX
     cleaaan = clean -dx
-    default-branch = !git rev-parse  --abbrev-ref origin/HEAD | cut -d/ -f2
+    default-branch = name-rev --name-only origin/HEAD
     dif = diff --color-words
     empty-commit = commit --allow-empty
 	exec = "!${SHELL:-/bin/sh} -ic "
-    ff = merge --no-edit --ff-only master
+    ff = merge --no-edit --ff-only origin/HEAD
     fixup = !cd "${GIT_PREFIX:-$PWD}" && git commit --fixup $(git last-commit)
     forget = reset HEAD^
     iec = commit --allow-empty --only --message \"Initial empty commit.\"
-    master = !git fetch --progress --tags "${1:-origin}" "$(git default-branch):$(git default-branch)"
     merg = merge --no-edit
     pop = stash pop
     posh = push --set-upstream origin HEAD
@@ -25,8 +24,6 @@
     Pull = pull --progress --ff --tags
     pull-force = !git fetch && git reset --hard "$(git tracking)"
     pushes = !git remote | xargs -n1 git push
-    remaster = !git master && git autorebase "$(git default-branch)"
-    rerebase = !git autorebase "$(git tracking)"
     retry = !cd "${GIT_PREFIX:-$PWD}" && git amend --no-edit . && git shove
     root = rev-parse --show-toplevel
     serve-git = daemon --reuseaddr --verbose --base-path=. --export-all ./.git
diff --git a/Documents/bin/git-master b/Documents/bin/git-master
new file mode 100755
index 0000000..ddd1662
--- /dev/null
+++ b/Documents/bin/git-master
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -eu
+
+# Update the default branch without checking out that branch (unless we're
+# already on the default branch, then just run git Pull. Accepts 1 paramter,
+# the remote name (defaults to origin).
+
+default_branch="$(git default-branch)"
+current_branch="$(git branch --show-current)"
+remote="${1:-origin}"
+
+if [ "$default_branch" = "$current_branch" ]
+then
+    git Pull
+else
+    git fetch --progress --tags "$remote" "$default_branch:$default_branch"
+fi
diff --git a/Documents/bin/git-remaster b/Documents/bin/git-remaster
new file mode 100755
index 0000000..7dce2f3
--- /dev/null
+++ b/Documents/bin/git-remaster
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -eu
+
+# Update the default branch using git-remaster, then rebase the current branch
+# on the default branch (unless we're already on the default branch, then we're
+# just run git Pull).
+
+default_branch="$(git default-branch)"
+current_branch="$(git branch --show-current)"
+
+if [ "$default_branch" = "$current_branch" ]
+then
+    git Pull
+else
+    git master
+    git autorebase "$default_branch"
+fi
-- 
GitLab