1
0
Fork 0
mirror of synced 2024-11-22 23:35:35 -05:00

[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 @@
# if ! is-true "$(commmand git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
fi fi
git fsck 2> /dev/null \ command git fsck 2> /dev/null \
| grep "^dangling commit" \ | grep "^dangling commit" \
| awk '{print $3}' \ | awk '{print $3}' \
| git log \ | command git log \
--date-order \ --date-order \
--no-walk \ --no-walk \
--stdin \ --stdin \

View file

@ -1,11 +1,4 @@
# local git_dir="${$(command git rev-parse --git-dir):A}"
# Displays the path to the Git directory.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local git_dir="${$(git rev-parse --git-dir):A}"
if [[ -n "${git_dir}" ]]; then if [[ -n "${git_dir}" ]]; then
print "${git_dir}" 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 # make sure we have a git-root
if ! git-root &> /dev/null; then if ! git-root &> /dev/null; then
print 'not in a git repository' >&2 print 'not in a git repository' >&2

View file

@ -1,11 +1,4 @@
# local root="$(command git rev-parse --show-toplevel 2> /dev/null)"
# 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)"
if [[ -n "${root}" ]]; then if [[ -n "${root}" ]]; then
print "${root}" print "${root}"

View file

@ -1,11 +1,4 @@
# if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
fi fi
@ -13,10 +6,10 @@ fi
local stashed local stashed
if [[ -f "$(git-dir)/refs/stash" ]]; then 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 (( ${stashed} > 0 )); then
if read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then if read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then
git stash clear command git stash clear
fi fi
fi fi
fi fi

View file

@ -1,19 +1,12 @@
# if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
fi fi
git fsck --unreachable 2> /dev/null \ command git fsck --unreachable 2> /dev/null \
| grep 'commit' \ | grep 'commit' \
| awk '{print $3}' \ | awk '{print $3}' \
| git log \ | command git log \
--pretty=format:${_git_log_oneline_format} \ --pretty=format:${_git_log_oneline_format} \
--extended-regexp \ --extended-regexp \
--grep="${1:-(WIP )?[Oo]n [^:]+:}" \ --grep="${1:-(WIP )?[Oo]n [^:]+:}" \

View file

@ -1,11 +1,4 @@
# if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
fi fi
@ -14,5 +7,5 @@ local commit
for commit in "${@}"; do for commit in "${@}"; do
git update-ref \ 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 done

View file

@ -1,11 +1,4 @@
# if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
elif [[ "${PWD}" != "$(git-root)" ]]; then elif [[ "${PWD}" != "$(git-root)" ]]; then
@ -17,7 +10,7 @@ local src="${1}"
local dst="${2}" local dst="${2}"
local url 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 if [[ -z "${url}" ]]; then
print "${0}: submodule not found: ${src}" >&2 print "${0}: submodule not found: ${src}" >&2

View file

@ -1,26 +1,19 @@
# if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
# 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
print "${0}: not a repository work tree: ${PWD}" >&2 print "${0}: not a repository work tree: ${PWD}" >&2
return 1 return 1
elif [[ "${PWD}" != "$(git-root)" ]]; then elif [[ "${PWD}" != "$(git-root)" ]]; then
print "${0}: must be run from the root of the work tree" >&2 print "${0}: must be run from the root of the work tree" >&2
return 1 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 print "${0}: submodule not found: ${1}" >&2
return 1 return 1
fi fi
git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null command git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null
git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null command git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null
git add .gitmodules command git add .gitmodules
git rm --cached -rf "${1}" command git rm --cached -rf "${1}"
rm -rf "${1}" rm -rf "${1}"
rm -rf "$(git-dir)/modules/${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]|)) ]]
}