[git] fix some functions

* remove unneeded explination and authorship comments (as it's
noted in the README.md)

* s/git/command git/ (see issue #30)

* add is-true function, as it is required by a few other functions.
This commit is contained in:
Matt Hamilton 2016-02-04 15:33:12 -05:00
parent cb12222811
commit 0c1aa6e133
10 changed files with 26 additions and 84 deletions

View File

@ -1,19 +1,12 @@
#
# Lists lost Git commits.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(commmand 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 \
command git fsck 2> /dev/null \
| grep "^dangling commit" \
| awk '{print $3}' \
| git log \
| command git log \
--date-order \
--no-walk \
--stdin \

View File

@ -1,11 +1,4 @@
#
# Displays the path to the Git directory.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local git_dir="${$(git rev-parse --git-dir):A}"
local git_dir="${$(command git rev-parse --git-dir):A}"
if [[ -n "${git_dir}" ]]; then
print "${git_dir}"

View File

@ -1,10 +1,3 @@
#
# Adds files passed as parameters to .gitignore in project root
#
# Authors:
# Matt Hamilton <m@tthamilton.com>
#
# make sure we have a git-root
if ! git-root &> /dev/null; then
print 'not in a git repository' >&2

View File

@ -1,11 +1,4 @@
#
# Displays the path to the working tree root.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
local root="$(command git rev-parse --show-toplevel 2> /dev/null)"
if [[ -n "${root}" ]]; then
print "${root}"

View File

@ -1,11 +1,4 @@
#
# Asks for confirmation before clearing the Git stash.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "${0}: not a repository work tree: ${PWD}" >&2
return 1
fi
@ -13,10 +6,10 @@ fi
local stashed
if [[ -f "$(git-dir)/refs/stash" ]]; then
stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')"
stashed="$(command git stash list 2> /dev/null | wc -l | awk '{print $1}')"
if (( ${stashed} > 0 )); then
if read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then
git stash clear
command git stash clear
fi
fi
fi

View File

@ -1,19 +1,12 @@
#
# Lists dropped Git stashed states.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(command 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 \
command git fsck --unreachable 2> /dev/null \
| grep 'commit' \
| awk '{print $3}' \
| git log \
| command git log \
--pretty=format:${_git_log_oneline_format} \
--extended-regexp \
--grep="${1:-(WIP )?[Oo]n [^:]+:}" \

View File

@ -1,11 +1,4 @@
#
# Recovers dropped Git stashed states.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
print "${0}: not a repository work tree: ${PWD}" >&2
return 1
fi
@ -14,5 +7,5 @@ local commit
for commit in "${@}"; do
git update-ref \
-m "$(git log -1 --pretty="format:%s" "$commit")" refs/stash "${commit}"
-m "$(command git log -1 --pretty="format:%s" "$commit")" refs/stash "${commit}"
done

View File

@ -1,11 +1,4 @@
#
# Moves a Git submodule.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(command 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
@ -17,7 +10,7 @@ local src="${1}"
local dst="${2}"
local url
url="$(git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")"
url="$(command git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")"
if [[ -z "${url}" ]]; then
print "${0}: submodule not found: ${src}" >&2

View File

@ -1,26 +1,19 @@
#
# Removes a Git submodule.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
if ! is-true "$(command 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
elif ! git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then
elif ! command git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then
print "${0}: submodule not found: ${1}" >&2
return 1
fi
git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null
git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null
git add .gitmodules
command git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null
command git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null
command git add .gitmodules
git rm --cached -rf "${1}"
command git rm --cached -rf "${1}"
rm -rf "${1}"
rm -rf "$(git-dir)/modules/${1}"

View File

@ -0,0 +1,5 @@
# Checks a boolean variable for "true".
# Case insensitive: "1", "y", "yes", "t", "true", "o", and "on".
is-true() {
[[ -n "$1" && "$1" == (1|[Yy]([Ee][Ss]|)|[Tt]([Rr][Uu][Ee]|)|[Oo]([Nn]|)) ]]
}