fixed git-changelog plugin

pull/1816/head
Gurkirat Singh 2021-01-24 18:01:51 +05:30 committed by Noah Gorny
parent 63f9f660a9
commit 77654875e5
2 changed files with 272 additions and 275 deletions

View File

@ -50,6 +50,7 @@ themes/modern
plugins/available/basher.plugin.bash plugins/available/basher.plugin.bash
plugins/available/cmd-returned-notify.plugin.bash plugins/available/cmd-returned-notify.plugin.bash
plugins/available/docker-machine.plugin.bash plugins/available/docker-machine.plugin.bash
plugins/available/git.plugin.bash
plugins/available/go.plugin.bash plugins/available/go.plugin.bash
plugins/available/goenv.plugin.bash plugins/available/goenv.plugin.bash
plugins/available/history.plugin.bash plugins/available/history.plugin.bash

View File

@ -1,3 +1,5 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'git helper functions' about-plugin 'git helper functions'
@ -57,11 +59,10 @@ function git_rollback() {
} }
function keep_changes() { function keep_changes() {
while true while true; do
do
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
case $RESP case $RESP in
in
[yY]) [yY])
echo "Rolling back to commit ${1} with unstaged changes" echo "Rolling back to commit ${1} with unstaged changes"
git reset $1 git reset $1
@ -74,6 +75,7 @@ function git_rollback() {
;; ;;
*) *)
echo "Please enter Y or N" echo "Please enter Y or N"
;;
esac esac
done done
} }
@ -82,11 +84,10 @@ function git_rollback() {
is_clean is_clean
commit_exists $1 commit_exists $1
while true while true; do
do
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
case $RESP case $RESP in
in
[yY]) [yY])
keep_changes $1 keep_changes $1
break break
@ -96,6 +97,7 @@ function git_rollback() {
;; ;;
*) *)
echo "Please enter Y or N" echo "Please enter Y or N"
;;
esac esac
done done
else else
@ -166,7 +168,7 @@ function git_stats {
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:" echo "Number of commits per author:"
git --no-pager shortlog -sn --all 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="" LOGOPTS=""
if [ "$1" == '-w' ]; then if [ "$1" == '-w' ]; then
LOGOPTS="$LOGOPTS -w" LOGOPTS="$LOGOPTS -w"
@ -180,8 +182,7 @@ function git_stats {
LOGOPTS="$LOGOPTS -C --find-copies-harder" LOGOPTS="$LOGOPTS -C --find-copies-harder"
shift shift
fi fi
for a in $AUTHORS for a in $AUTHORS; do
do
echo '-------------------' echo '-------------------'
echo "Statistics for: $a" echo "Statistics for: $a"
echo -n "Number of files changed: " echo -n "Number of files changed: "
@ -204,7 +205,7 @@ function gittowork() {
param '1: the language/type of the project, used for determining the contents of the .gitignore file' param '1: the language/type of the project, used for determining the contents of the .gitignore file'
example '$ gittowork java' 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 if [[ $result =~ ERROR ]]; then
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'" echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
@ -212,7 +213,7 @@ function gittowork() {
echo "$result" echo "$result"
else else
if [[ -f .gitignore ]]; then 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 ".gitignore already exists, appending..."
echo "$result" >> .gitignore echo "$result" >> .gitignore
else else
@ -237,24 +238,21 @@ function gitignore-reload() {
err=0 err=0
# Disallow unstaged changes in the working tree # Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules -- if ! git diff-files --quiet --ignore-submodules --; then
then
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes." echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2 git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1 err=1
fi fi
# Disallow uncommited changes in the index # Disallow uncommited changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules if ! git diff-index --cached --quiet HEAD --ignore-submodules; then
then
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes." echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2 git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1 err=1
fi fi
# Prompt user to commit or stash changes and exit # Prompt user to commit or stash changes and exit
if [ $err = 1 ] if [ $err = 1 ]; then
then
echo >&2 "Please commit or stash them." echo >&2 "Please commit or stash them."
fi fi
@ -274,7 +272,7 @@ function gitignore-reload() {
fi fi
} }
function git-changelog(){ function git-changelog() {
# --------------------------------------------------------------- # ---------------------------------------------------------------
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 | # ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
# --------------------------------------------------------------- # ---------------------------------------------------------------
@ -282,31 +280,29 @@ function git-changelog(){
group 'git' group 'git'
example '$ git-changelog origin/master...origin/release [md|txt]' example '$ git-changelog origin/master...origin/release [md|txt]'
if [[ "$1" != *"..."* ]] if [[ "$1" != *"..."* ]]; then
then
echo "Please include the valid 'diff' to make changelog" echo "Please include the valid 'diff' to make changelog"
return 1 return 1
fi fi
local NEXT=$(date +%F) local NEXT=$(date +%F)
if [[ "$2" == "md" ]] if [[ "$2" == "md" ]]; then
then
echo "# CHANGELOG $1" echo "# CHANGELOG $1"
git log $1 --no-merges --format="%cd" --date=short | sort -u -r | while read DATE ; do git log $1 --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo echo
echo "### $DATE" echo "### $DATE"
GIT_PAGER=cat git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00" git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
NEXT=$DATE NEXT=$DATE
done done
else else
echo "CHANGELOG $1" echo "CHANGELOG $1"
echo ---------------------- echo ----------------------
git log $1 --no-merges --format="%cd" --date=short | sort -u -r | while read DATE ; do git log $1 --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo echo
echo [$DATE] echo [$DATE]
GIT_PAGER=cat git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
NEXT=$DATE NEXT=$DATE
done done
fi fi