Make sure that the current directory is a Git repository

This commit is contained in:
Sorin Ionescu 2012-09-30 15:30:18 -04:00
parent 6c1a81b5cf
commit 102da8bea0
12 changed files with 55 additions and 10 deletions

View File

@ -8,6 +8,10 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
return 1
fi
local state expl remotes remote branches_or_tags branches tags files ret=1
_arguments -C -s -S \

View File

@ -8,6 +8,10 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
return 1
fi
_arguments "1:toggle:((
on\:'enable in-prompt information for the current repository'
off\:'disable in-prompt information for the current repository'

View File

@ -5,7 +5,13 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! git rev-parse 2> /dev/null; then
print "$0: not a repository: $PWD" >&2
return 1
fi
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
if [[ -n "$ref" ]]; then
print "${ref#refs/heads/}"
return 0

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
git fsck 2> /dev/null \
| grep "^dangling commit" \
| awk '{print $3}' \

View File

@ -11,6 +11,7 @@ if [[ -n "$git_dir" ]]; then
print "$git_dir"
return 0
else
print "$0: not a repository: $PWD" >&2
return 1
fi

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
local remotes remote references reference file url
remote="${1:-origin}"

View File

@ -11,6 +11,7 @@ if [[ -n "$root" ]]; then
print "$root"
return 0
else
print "$0: not a repository work tree: $PWD" >&2
return 1
fi

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
local stashed
if [[ -f "$(git-dir)/refs/stash" ]]; then

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
git fsck --unreachable 2> /dev/null \
| grep 'commit' \
| awk '{print $3}' \

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
local commit
for commit in "$@"; do

View File

@ -5,15 +5,18 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
elif [[ "$PWD" != "$(git-root)" ]]; then
print "$0: must be run from the root of the work tree" >&2
return 1
fi
local src="$1"
local dst="$2"
local url
if [[ "$PWD" != "$(git-root)" ]]; then
print "$0: must be run from the root of the working tree" >&2
return 1
fi
url="$(git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")"
if [[ -z "$url" ]]; then

View File

@ -5,12 +5,13 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if [[ "$PWD" != "$(git-root)" ]]; then
print "$0: must be run from the root of the working tree" >&2
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "$0: not a repository work tree: $PWD" >&2
return 1
fi
if ! git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then
elif [[ "$PWD" != "$(git-root)" ]]; then
print "$0: must be run from the root of the work tree" >&2
return 1
elif ! git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then
print "$0: submodule not found: $1" >&2
return 1
fi