Fail git status if .git not in cwd or parent directory
This commit is contained in:
8
lib/git/helpers.sh
Normal file
8
lib/git/helpers.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function find_in_cwd_or_parent() {
|
||||||
|
local slashes=${PWD//[^\/]/}; local directory=$PWD;
|
||||||
|
for (( n=${#slashes}; n>0; --n )); do
|
||||||
|
test -e "$directory/$1" && echo "$directory/$1" && return 0
|
||||||
|
directory="$directory/.."
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
@@ -17,6 +17,11 @@
|
|||||||
# 1 || staged, 2 || unmerged, 3 || unstaged, 4 || untracked
|
# 1 || staged, 2 || unmerged, 3 || unstaged, 4 || untracked
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
git_status_shortcuts() {
|
git_status_shortcuts() {
|
||||||
|
# Fail if not a git repo
|
||||||
|
if ! find_in_cwd_or_parent ".git" > /dev/null; then
|
||||||
|
echo -e "\e[31mNot a git repository (or any of the parent directories)\e[0m"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
zsh_compat # Ensure shwordsplit is on for zsh
|
zsh_compat # Ensure shwordsplit is on for zsh
|
||||||
git_clear_vars
|
git_clear_vars
|
||||||
# Run ruby script, store output
|
# Run ruby script, store output
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export scmbDir="$(dirname ${BASH_SOURCE:-$0})"
|
|||||||
if [[ -s "$HOME/.git.scmbrc" ]]; then
|
if [[ -s "$HOME/.git.scmbrc" ]]; then
|
||||||
# Load git config
|
# Load git config
|
||||||
. "$HOME/.git.scmbrc"
|
. "$HOME/.git.scmbrc"
|
||||||
|
. "$scmbDir/lib/git/helpers.sh"
|
||||||
. "$scmbDir/lib/git/aliases.sh"
|
. "$scmbDir/lib/git/aliases.sh"
|
||||||
. "$scmbDir/lib/git/keybindings.sh"
|
. "$scmbDir/lib/git/keybindings.sh"
|
||||||
. "$scmbDir/lib/git/status_shortcuts.sh"
|
. "$scmbDir/lib/git/status_shortcuts.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user