Make sure that the current directory is a Git repository
This commit is contained in:
parent
6c1a81b5cf
commit
102da8bea0
@ -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 \
|
||||||
|
@ -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'
|
||||||
|
@ -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
|
||||||
|
@ -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}' \
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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}"
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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}' \
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user