Skip to main content

Handle running gm and gp from a nested folder of the Git repo

ID
c4aa746
date
2025-05-28 06:46:06+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
fc7d210
message
Handle running `gm` and `gp` from a nested folder of the Git repo
changed files
2 files, 5 additions, 2 deletions

Changed files

git/gm (1659) → git/gm (1708)

diff --git a/git/gm b/git/gm
index 9c025d3..7d68181 100755
--- a/git/gm
+++ b/git/gm
@@ -4,6 +4,8 @@
 set -o errexit
 set -o nounset
 
+ROOT="$(git rev-parse --show-toplevel)"
+
 # Checking for the branch first is a bit slower, but avoids a potentially
 # confusing warning immediately before the pull:
 #
@@ -30,7 +32,7 @@ cleanup_branches
 if [[ $(groot) = ~/repos/alexwlchan.net ]] || \
    [[ $(groot) = ~/repos/books.alexwlchan.net ]]
 then
-  if grep -q 'Gemfile' .git/names_diff.txt
+  if grep -q 'Gemfile' "$ROOT/.git/names_diff.txt"
   then
     echo ""
 

git/gp (781) → git/gp (829)

diff --git a/git/gp b/git/gp
index 97c18e5..cf25781 100755
--- a/git/gp
+++ b/git/gp
@@ -9,6 +9,7 @@ set -o nounset
 
 _ensure_ssh_key_loaded
 
+ROOT="$(git rev-parse --show-toplevel)"
 HEAD="$(git rev-parse --abbrev-ref HEAD)"
 
 # This avoids any clashes with other programs called "gp", e.g. at one
@@ -18,7 +19,7 @@ $(dirname "$0")/gf
 echo ""
 
 # Log a list of files which will be changed to .git/names_diff.txt
-git diff --name-status "$HEAD" "origin/$HEAD" > .git/names_diff.txt 2>/dev/null
+git diff --name-status "$HEAD" "origin/$HEAD" > "$ROOT/.git/names_diff.txt" 2>/dev/null
 
 if [[ "${1:-}" == "--rebase" ]]
 then