1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 23:08:00 +00:00

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> # 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 local state expl remotes remote branches_or_tags branches tags files ret=1
_arguments -C -s -S \ _arguments -C -s -S \

View File

@ -8,6 +8,10 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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:(( _arguments "1:toggle:((
on\:'enable in-prompt information for the current repository' on\:'enable in-prompt information for the current repository'
off\:'disable 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> # 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)" local ref="$(git symbolic-ref HEAD 2> /dev/null)"
if [[ -n "$ref" ]]; then if [[ -n "$ref" ]]; then
print "${ref#refs/heads/}" print "${ref#refs/heads/}"
return 0 return 0

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 \ git fsck 2> /dev/null \
| grep "^dangling commit" \ | grep "^dangling commit" \
| awk '{print $3}' \ | awk '{print $3}' \

View File

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

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 local remotes remote references reference file url
remote="${1:-origin}" remote="${1:-origin}"

View File

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

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 local stashed
if [[ -f "$(git-dir)/refs/stash" ]]; then if [[ -f "$(git-dir)/refs/stash" ]]; then

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 \ git fsck --unreachable 2> /dev/null \
| grep 'commit' \ | grep 'commit' \
| awk '{print $3}' \ | awk '{print $3}' \

View File

@ -5,6 +5,11 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 local commit
for commit in "$@"; do for commit in "$@"; do

View File

@ -5,15 +5,18 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # 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 src="$1"
local dst="$2" local dst="$2"
local url 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")" url="$(git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")"
if [[ -z "$url" ]]; then if [[ -z "$url" ]]; then

View File

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