Skip to main content

Add a bit more debugging to my Git scripts

ID
960cf9d
date
2025-04-23 05:51:50+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
2a382b3
message
Add a bit more debugging to my Git scripts
changed files
5 files, 33 additions, 7 deletions

Changed files

git/README.md (7624) → git/README.md (8029)

diff --git a/git/README.md b/git/README.md
index 83dd2e4..b159f1a 100644
--- a/git/README.md
+++ b/git/README.md
@@ -114,6 +114,12 @@ scripts = [
         open the current Git repo in <a href="https://gitup.co/">GitUp</a>, my GUI Git client of choice
         """
     },
+    {
+        "usage": "print_info [MESSAGE]",
+        "description": """
+        helper script that lets me print text in blue inside other Git scripts
+        """
+    },
 ]
 
 cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
@@ -267,5 +273,14 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
   <dd>
     open the current Git repo in <a href="https://gitup.co/">GitUp</a>, my GUI Git client of choice
   </dd>
+
+  <dt>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/git/print_info">
+      <code>print_info [MESSAGE]</code>
+    </a>
+  </dt>
+  <dd>
+    helper script that lets me print text in blue inside other Git scripts
+  </dd>
 </dl>
-<!-- [[[end]]] (checksum: 113cfe8c833dfc74985f3f7dff2bcace) -->
+<!-- [[[end]]] (checksum: 8e699083c35f78871a88e9bf6ca053bd) -->

git/gf (281) → git/gf (322)

diff --git a/git/gf b/git/gf
index 6a67982..69f8722 100755
--- a/git/gf
+++ b/git/gf
@@ -9,4 +9,5 @@ set -o nounset
 
 _ensure_ssh_key_loaded
 
+print_info "-> git fetch origin --prune"
 git fetch origin --prune

git/gm (456) → git/gm (520)

diff --git a/git/gm b/git/gm
index 2794b8e..29b94af 100755
--- a/git/gm
+++ b/git/gm
@@ -4,8 +4,6 @@
 set -o errexit
 set -o nounset
 
-_ensure_ssh_key_loaded
-
 # Checking for the branch first is a bit slower, but avoids a potentially
 # confusing warning immediately before the pull:
 #
@@ -14,6 +12,8 @@ _ensure_ssh_key_loaded
 #
 if [[ $(gcb) != $(_get_primary_branch) ]]
 then
+  print_info "-> git checkout $(_get_primary_branch)"
+  print_info "   (Was on $(gcb))"
   git checkout "$(_get_primary_branch)"
 fi
 

git/gp (287) → git/gp (325)

diff --git a/git/gp b/git/gp
index f11d9d6..495348e 100755
--- a/git/gp
+++ b/git/gp
@@ -6,11 +6,15 @@ set -o nounset
 
 _ensure_ssh_key_loaded
 
+HEAD="$(git rev-parse --abbrev-ref HEAD)"
+
+gf
+
 if [[ "${1:-}" == "--rebase" ]]
 then
-  git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase
+  print_info "-> git rebase $HEAD"
+  git rebase "$HEAD"
 else
-  git pull origin $(git rev-parse --abbrev-ref HEAD)
+  print_info "-> git merge $HEAD"
+  git merge "$HEAD"
 fi
-
-gf

git/print_info (0) → git/print_info (80)

diff --git a/git/print_info b/git/print_info
new file mode 100755
index 0000000..88cf169
--- /dev/null
+++ b/git/print_info
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+echo -e "\033[34m$1\033[0m"