Skip to content

Commit 4695490

Browse files
authored
fix: Use git to figure out git repo. (#351)
I have a `.git` directory in my `$HOME` for some git hooks I have but it isn't a git repo and confuses me when I open a new terminal and forget I'm in my home but I get the 'There were more than 150 changed files.' I've included how it should look with the `/tmp` directory. See screenshot. <img width="843" height="175" alt="ss 2025-08-04 at 12 33 52 PM" src="https://github.com/user-attachments/assets/d2eaf852-c298-40d8-bace-b67a54df2a5e" /> This removes the `find_in_cwd_or_parent` shell method in favor of just using a `git` command to determine. Seems simpler and more stable since it uses built-in git behaviour instead of rolling our own method.
2 parents 226ad22 + 0cc8b15 commit 4695490

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/git/helpers.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
function find_in_cwd_or_parent() {
2-
local slashes=${PWD//[^\/]/}; local directory=$PWD;
3-
for (( n=${#slashes}; n>0; --n )); do
4-
test -e "$directory/$1" && echo "$directory/$1" && return 0
5-
directory="$directory/.."
6-
done
7-
return 1
8-
}
9-
101
function fail_if_not_git_repo() {
11-
if ! find_in_cwd_or_parent ".git" > /dev/null; then
2+
local gcmd=${_git_cmd:-git}
3+
4+
if ! "${gcmd}" rev-parse --show-toplevel &> /dev/null; then
125
echo -e "\033[31mNot a git repository (or any of the parent directories)\033[0m"
136
return 1
147
fi

0 commit comments

Comments
 (0)