Really detect new and deleted branches
This commit is contained in:
parent
4a9a8cc4de
commit
792d31a6b7
|
@ -76,43 +76,67 @@ _hook_update()
|
||||||
refname="$1"
|
refname="$1"
|
||||||
oldrev="$2"
|
oldrev="$2"
|
||||||
newrev="$3"
|
newrev="$3"
|
||||||
|
nullrev="0000000000000000000000000000000000000000"
|
||||||
author="$GL_USER"
|
author="$GL_USER"
|
||||||
|
[ -z "$author" ] && author="$USER"
|
||||||
repository="$GL_REPO"
|
repository="$GL_REPO"
|
||||||
branch=
|
branch=
|
||||||
type=$($GIT cat-file -t "$newrev")
|
|
||||||
|
|
||||||
|
#analyze the push
|
||||||
|
message=
|
||||||
|
[ -n "$repository" ] && message="$repository:"
|
||||||
|
[ -n "$author" ] && message="$message $author"
|
||||||
|
branch=
|
||||||
case "$refname" in
|
case "$refname" in
|
||||||
refs/heads/*)
|
refs/heads/*)
|
||||||
branch=${refname#refs/heads/}
|
branch=${refname#refs/heads/}
|
||||||
|
[ -n "$branch" ] && message="$message [$branch]"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
[ -n "$refname" ] && message="$message [$refname]"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
if [ "$oldrev" = "$nullrev" ]; then
|
||||||
#analyze each commit pushed
|
message="$message new branch"
|
||||||
revisions=$($GIT rev-list "${oldrev}..${newrev}")
|
elif [ "$newrev" = "$nullrev" ]; then
|
||||||
message=
|
message="$message branch deleted"
|
||||||
commit_cnt=0
|
|
||||||
all_files=
|
|
||||||
for revision in $revisions; do
|
|
||||||
#$GIT cat-file commit "$revision"
|
|
||||||
#count the file alterations
|
|
||||||
files=$($GIT log -n 1 --name-only --pretty=format:'' "$revision")
|
|
||||||
[ -z "$message" ] && message=$($GIT log -n 1 --oneline "$revision")
|
|
||||||
all_files="$all_files$files"
|
|
||||||
#count the number of commits
|
|
||||||
commit_cnt=$((commit_cnt + 1))
|
|
||||||
done
|
|
||||||
all_files=$(echo "$all_files" | $SED -e '/^$/d')
|
|
||||||
files_cnt=$(echo "$all_files" | $WC -l)
|
|
||||||
unique_files_cnt=$(echo "$all_files" | $SORT | $UNIQ | $WC -l)
|
|
||||||
if [ -n "$branch" ]; then
|
|
||||||
if [ $commit_cnt -eq 1 -a -n "$message" ]; then
|
|
||||||
echo "$repository: $author [$branch] $message ($files_cnt alterations in $unique_files_cnt files)"
|
|
||||||
else
|
|
||||||
echo "$repository: $author [$branch] $commit_cnt $type(s) pushed ($files_cnt alterations in $unique_files_cnt files)"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "$repository: $author [$refname] $commit_cnt $type(s) pushed ($files_cnt alterations in $unique_files_cnt files)"
|
commit_cnt=0
|
||||||
|
all_files=
|
||||||
|
revisions=$($GIT rev-list "${oldrev}..${newrev}")
|
||||||
|
type=$($GIT cat-file -t "$newrev")
|
||||||
|
log=
|
||||||
|
for revision in $revisions; do
|
||||||
|
#$GIT cat-file commit "$revision"
|
||||||
|
#obtain the first log message
|
||||||
|
[ -z "$log" ] && log=$($GIT log -n 1 --oneline "$revision")
|
||||||
|
#count the file alterations
|
||||||
|
files=$($GIT log -n 1 --name-only --pretty=format:'' "$revision")
|
||||||
|
all_files="$all_files$files"
|
||||||
|
#count the number of commits
|
||||||
|
commit_cnt=$((commit_cnt + 1))
|
||||||
|
done
|
||||||
|
all_files=$(echo "$all_files" | $SED -e '/^$/d')
|
||||||
|
files_cnt=$(echo "$all_files" | $WC -l)
|
||||||
|
unique_files_cnt=$(echo "$all_files" | $SORT | $UNIQ | $WC -l)
|
||||||
|
if [ $commit_cnt -eq 1 -a -n "$log" ]; then
|
||||||
|
message="$message $log"
|
||||||
|
else
|
||||||
|
message="$message $commit_cnt $type(s) pushed"
|
||||||
|
fi
|
||||||
|
message="$message ($files_cnt"
|
||||||
|
if [ $files_cnt -lt 2 ]; then
|
||||||
|
message="$message alteration"
|
||||||
|
else
|
||||||
|
message="$message alterations"
|
||||||
|
fi
|
||||||
|
if [ $unique_files_cnt -lt 2 ]; then
|
||||||
|
message="$message in $unique_files_cnt file)"
|
||||||
|
else
|
||||||
|
message="$message in $unique_files_cnt files)"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
echo "$message"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user