commit
fe9ef1e4bd
|
|
@ -50,6 +50,7 @@ themes/modern
|
|||
plugins/available/basher.plugin.bash
|
||||
plugins/available/cmd-returned-notify.plugin.bash
|
||||
plugins/available/docker-machine.plugin.bash
|
||||
plugins/available/git.plugin.bash
|
||||
plugins/available/go.plugin.bash
|
||||
plugins/available/goenv.plugin.bash
|
||||
plugins/available/history.plugin.bash
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'git helper functions'
|
||||
|
||||
function git_remote {
|
||||
about 'adds remote $GIT_HOSTING:$1 to current repo'
|
||||
group 'git'
|
||||
about "adds remote $GIT_HOSTING:$1 to current repo"
|
||||
group "git"
|
||||
|
||||
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
|
||||
git remote add origin $GIT_HOSTING:$1.git
|
||||
git remote add origin "$GIT_HOSTING:$1".git
|
||||
}
|
||||
|
||||
function git_first_push {
|
||||
|
|
@ -23,15 +24,15 @@ function git_pub() {
|
|||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
echo "Publishing ${BRANCH} to remote origin"
|
||||
git push -u origin $BRANCH
|
||||
git push -u origin "$BRANCH"
|
||||
}
|
||||
|
||||
function git_revert() {
|
||||
about 'applies changes to HEAD that revert all changes after this commit'
|
||||
group 'git'
|
||||
|
||||
git reset $1
|
||||
git reset --soft HEAD@{1}
|
||||
git reset "$1"
|
||||
git reset --soft "HEAD@{1}"
|
||||
git commit -m "Revert to ${1}"
|
||||
git reset --hard
|
||||
}
|
||||
|
|
@ -48,7 +49,7 @@ function git_rollback() {
|
|||
}
|
||||
|
||||
function commit_exists() {
|
||||
git rev-list --quiet $1
|
||||
git rev-list --quiet "$1"
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Commit ${1} does not exist"
|
||||
|
|
@ -57,38 +58,39 @@ function git_rollback() {
|
|||
}
|
||||
|
||||
function keep_changes() {
|
||||
while true
|
||||
do
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
||||
case $RESP
|
||||
in
|
||||
case $RESP in
|
||||
|
||||
[yY])
|
||||
echo "Rolling back to commit ${1} with unstaged changes"
|
||||
git reset $1
|
||||
git reset "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
echo "Rolling back to commit ${1} with a clean working tree"
|
||||
git reset --hard $1
|
||||
git reset --hard "$1"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
is_clean
|
||||
commit_exists $1
|
||||
commit_exists "$1"
|
||||
|
||||
while true
|
||||
do
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
|
||||
case $RESP
|
||||
in
|
||||
case $RESP in
|
||||
|
||||
[yY])
|
||||
keep_changes $1
|
||||
keep_changes "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
|
|
@ -96,6 +98,7 @@ function git_rollback() {
|
|||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
|
|
@ -131,8 +134,8 @@ function git_info() {
|
|||
|
||||
# print all remotes and thier details
|
||||
for remote in $(git remote show); do
|
||||
echo $remote:
|
||||
git remote show $remote
|
||||
echo "$remote":
|
||||
git remote show "$remote"
|
||||
echo
|
||||
done
|
||||
|
||||
|
|
@ -160,13 +163,13 @@ function git_stats {
|
|||
about 'display stats per author'
|
||||
group 'git'
|
||||
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
echo "Number of commits per author:"
|
||||
git --no-pager shortlog -sn --all
|
||||
AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
LOGOPTS=""
|
||||
if [ "$1" == '-w' ]; then
|
||||
LOGOPTS="$LOGOPTS -w"
|
||||
|
|
@ -180,22 +183,25 @@ if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
|||
LOGOPTS="$LOGOPTS -C --find-copies-harder"
|
||||
shift
|
||||
fi
|
||||
for a in $AUTHORS
|
||||
do
|
||||
for a in $AUTHORS; do
|
||||
echo '-------------------'
|
||||
echo "Statistics for: $a"
|
||||
echo -n "Number of files changed: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l
|
||||
echo -n "Number of lines added: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of lines deleted: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of merges: "
|
||||
git log $LOGOPTS --all --merges --author=$a | grep -c '^commit'
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit'
|
||||
done
|
||||
else
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function gittowork() {
|
||||
|
|
@ -204,7 +210,7 @@ function gittowork() {
|
|||
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
||||
example '$ gittowork java'
|
||||
|
||||
result=$(curl -L "https://www.gitignore.io/api/$1" 2>/dev/null)
|
||||
result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null)
|
||||
|
||||
if [[ $result =~ ERROR ]]; then
|
||||
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
|
||||
|
|
@ -212,7 +218,7 @@ function gittowork() {
|
|||
echo "$result"
|
||||
else
|
||||
if [[ -f .gitignore ]]; then
|
||||
result=`echo "$result" | grep -v "# Created by http://www.gitignore.io"`
|
||||
result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io")
|
||||
echo ".gitignore already exists, appending..."
|
||||
echo "$result" >> .gitignore
|
||||
else
|
||||
|
|
@ -237,24 +243,21 @@ function gitignore-reload() {
|
|||
err=0
|
||||
|
||||
# Disallow unstaged changes in the working tree
|
||||
if ! git diff-files --quiet --ignore-submodules --
|
||||
then
|
||||
if ! git diff-files --quiet --ignore-submodules --; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Disallow uncommited changes in the index
|
||||
if ! git diff-index --cached --quiet HEAD --ignore-submodules
|
||||
then
|
||||
if ! git diff-index --cached --quiet HEAD --ignore-submodules; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Prompt user to commit or stash changes and exit
|
||||
if [ $err = 1 ]
|
||||
then
|
||||
if [ $err = 1 ]; then
|
||||
echo >&2 "Please commit or stash them."
|
||||
fi
|
||||
|
||||
|
|
@ -273,3 +276,42 @@ function gitignore-reload() {
|
|||
echo >&2 "Files readded. Commit your new changes now."
|
||||
fi
|
||||
}
|
||||
|
||||
function git-changelog() {
|
||||
# ---------------------------------------------------------------
|
||||
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
|
||||
# ---------------------------------------------------------------
|
||||
about 'Creates the git changelog from one point to another by date'
|
||||
group 'git'
|
||||
example '$ git-changelog origin/master...origin/release [md|txt]'
|
||||
|
||||
if [[ "$1" != *"..."* ]]; then
|
||||
echo "Please include the valid 'diff' to make changelog"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local NEXT=$(date +%F)
|
||||
|
||||
if [[ "$2" == "md" ]]; then
|
||||
echo "# CHANGELOG $1"
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo "### $DATE"
|
||||
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
|
||||
NEXT=$DATE
|
||||
done
|
||||
else
|
||||
echo "CHANGELOG $1"
|
||||
echo ----------------------
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo [$DATE]
|
||||
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
|
||||
NEXT=$DATE
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue