2018-02-08 15:09:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
|
|
|
|
|
|
|
prepareGitAuth $CONFIG_DIR
|
|
|
|
|
|
|
|
|
2018-02-22 22:09:11 +01:00
|
|
|
# if detector is not enabled, quit quietly
|
|
|
|
if ! detectorRunCapable
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
source $mydir/detector-lib-git
|
2018-02-25 20:00:02 +01:00
|
|
|
source $mydir/detector-lib-general
|
2018-02-22 22:09:11 +01:00
|
|
|
|
|
|
|
detectorLoadConfig
|
|
|
|
|
|
|
|
repodir=$(gen-mirror-path $repo)
|
|
|
|
|
|
|
|
if detectorCheckFetchHead $repodir
|
|
|
|
then
|
|
|
|
# nothing changed, just die
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-02-25 20:43:54 +01:00
|
|
|
# try to init cache
|
|
|
|
detectorTryInit $repodir
|
|
|
|
|
2018-02-22 22:09:11 +01:00
|
|
|
# first, solve commits
|
2018-02-25 20:00:02 +01:00
|
|
|
# branches that were deleted or merged
|
|
|
|
find $DET_BRANCHES -type f | sort | while read branchpath
|
|
|
|
do
|
|
|
|
branch=$(basename $branchpath)
|
|
|
|
if ! gitListBranches $repodir | grep -q "^$branch$"
|
|
|
|
then
|
|
|
|
echo "Unexistent branch <$branch>!!"
|
|
|
|
# rm it, should be merget etc...
|
|
|
|
rm $DET_BRANCHES/$branch
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# new branches or new commits in curent branches
|
|
|
|
# firstly list master branch, to make first commits in it
|
|
|
|
gitPrefBranches $repodir | while read branch
|
|
|
|
do
|
|
|
|
[ -f $DET_BRANCHES/$branch ] || touch $DET_BRANCHES/$branch
|
|
|
|
oldsha=$(cat $DET_BRANCHES/$branch)
|
|
|
|
newsha=$(git --git-dir $repodir show-ref --heads $branch | cut -d' ' -f1)
|
|
|
|
[ -z "$oldsha" ] || oldsha=$oldsha..
|
|
|
|
# walk through every commit in branch (since last change)
|
|
|
|
for commitId in $(git --no-pager --git-dir $repodir log --reverse --format="%H" $oldsha$branch)
|
|
|
|
do
|
|
|
|
if detectorCheckCommit $commitId
|
|
|
|
then
|
|
|
|
# commit was not processed - start
|
|
|
|
# COMMIT = $commitId
|
|
|
|
# COMMIT_AUTHOR = $author
|
|
|
|
author=$(git --git-dir $repodir log $commitId -1 --format="%an <%ae>")
|
2018-03-02 11:25:49 +01:00
|
|
|
# COMMIT_ABBREV
|
|
|
|
abbr=$(git --git-dir $repodir log $commitId -1 --format="%h")
|
|
|
|
# COMMIT_LOG
|
|
|
|
log=$(git --git-dir $repodir log $commitId -1 --format="%s")
|
2018-02-25 20:00:02 +01:00
|
|
|
# BRANCH = $branch
|
|
|
|
# PORJECT_NAME = $cloner_project_name
|
|
|
|
|
|
|
|
set +e
|
2018-03-02 11:25:49 +01:00
|
|
|
COMMIT="$commitId" \
|
2018-02-25 20:00:02 +01:00
|
|
|
COMMIT_AUTHOR="$author" \
|
|
|
|
COMMIT_BRANCH="$branch" \
|
2018-03-02 11:25:49 +01:00
|
|
|
COMMIT_ABBREV="$abbr" \
|
|
|
|
COMMIT_LOG="$log" \
|
2018-02-25 20:00:02 +01:00
|
|
|
PROJECT_NAME="$cloner_project_name" \
|
|
|
|
notify-commit
|
2018-03-02 11:25:49 +01:00
|
|
|
rc=$?
|
|
|
|
[ $rc -eq 0 ] || echo "Notify $branch/$commitId: return code = $rc"
|
2018-02-25 20:00:02 +01:00
|
|
|
set -e
|
|
|
|
detectorSaveCommit $commitId
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
echo $newsha > $DET_BRANCHES/$branch
|
|
|
|
done
|
|
|
|
|
2018-02-22 22:09:11 +01:00
|
|
|
|
|
|
|
# solve tags - remove nonexistent refs
|
|
|
|
find $DET_TAGS -type f | sort | while read tagname
|
|
|
|
do
|
2018-03-23 22:10:02 +01:00
|
|
|
tag=$(basename $tagname)
|
2018-03-24 14:15:50 +01:00
|
|
|
if ! git --git-dir="$repodir" rev-parse "tags/$tag" > /dev/null 2>&1
|
2018-02-22 22:09:11 +01:00
|
|
|
then
|
|
|
|
echo "Removing tag: $tag (was [$(cat $tagname)])"
|
|
|
|
rm $tagname
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-02-23 11:42:13 +01:00
|
|
|
# tags that changed or were pushed as new
|
2018-02-25 20:00:02 +01:00
|
|
|
gitListTags $repodir | while read tagname
|
2018-02-22 22:09:11 +01:00
|
|
|
do
|
|
|
|
[ -f $DET_TAGS/$tagname ] || touch $DET_TAGS/$tagname
|
|
|
|
oldsha=$(cat $DET_TAGS/$tagname)
|
2018-02-25 20:00:02 +01:00
|
|
|
newsha=$(git --git-dir $repodir show-ref --tags $tagname | cut -d' ' -f1)
|
2019-06-11 23:45:03 +02:00
|
|
|
if ! [ "x$oldsha" = "x$newsha" ]
|
2018-02-22 22:09:11 +01:00
|
|
|
then
|
|
|
|
# TAG_HASH = $newsha
|
2018-02-23 11:42:13 +01:00
|
|
|
# TAG_NAME = $tagname
|
2018-02-22 22:09:11 +01:00
|
|
|
# TAG_AUTHOR
|
2018-02-23 11:42:13 +01:00
|
|
|
author=$(git --git-dir $repodir log $newsha -1 --pretty=format:"%an <%ae>")
|
2018-03-02 11:25:49 +01:00
|
|
|
# TAG_ABBREV
|
|
|
|
abbr=$(git --git-dir $repodir log $newsha -1 --format="%h")
|
|
|
|
# TAG_LOG
|
|
|
|
log=$(git --git-dir $repodir log $newsha -1 --format="%s")
|
2018-02-23 11:42:13 +01:00
|
|
|
# PROJECT_NAME = $cloner_project_name
|
2018-03-02 11:25:49 +01:00
|
|
|
|
2018-02-23 11:42:13 +01:00
|
|
|
# call the notify script
|
|
|
|
set +e
|
2018-03-02 11:25:49 +01:00
|
|
|
TAG_HASH="$newsha" \
|
2018-02-23 11:42:13 +01:00
|
|
|
TAG_NAME="$tagname" \
|
|
|
|
TAG_AUTHOR="$author" \
|
2018-03-02 11:25:49 +01:00
|
|
|
TAG_ABBREV="$abbr" \
|
|
|
|
TAG_LOG="$log" \
|
|
|
|
PROJECT_NAME="$cloner_project_name" notify-tag
|
2018-02-23 11:42:13 +01:00
|
|
|
rc=$?
|
|
|
|
[ $rc -eq 0 ] || echo "Notify $tagname: return code = $rc"
|
|
|
|
set -e
|
2018-02-22 22:09:11 +01:00
|
|
|
fi
|
2018-02-25 20:00:02 +01:00
|
|
|
echo $newsha > $DET_TAGS/$tagname
|
2018-02-22 22:09:11 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# save hash to keep things clear
|
2018-02-25 20:43:54 +01:00
|
|
|
detectorSumPersist $repodir
|
2018-02-08 15:09:47 +01:00
|
|
|
|