fixed git-changelog plugin

pull/1815/head
Gurkirat Singh 2021-01-24 18:01:51 +05:30
parent e189254ba3
commit 9cf0ec24eb
No known key found for this signature in database
GPG Key ID: CFD64E1DCB3DA835
2 changed files with 272 additions and 275 deletions

View File

@ -43,6 +43,7 @@ themes/base.theme.bash
# plugins # plugins
# #
plugins/available/basher.plugin.bash plugins/available/basher.plugin.bash
plugins/available/git.plugin.bash
# completions # completions
# #

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
@ -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: "
@ -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
@ -282,22 +280,20 @@ 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
@ -306,7 +302,7 @@ function git-changelog(){
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