Gitlog2wiki

From BITPlan Wiki
Jump to navigation Jump to search
#!/bin/bash
# WF 2018-10-25
# convert git log to Semantic MediaWiki commit

# example
# commit 5a2a4ef73bde4d20acf2d43069b08dec58e5ecd4
#Author: Wolfgang Fahl <wf@bitplan.com>
#Date:   2018-10-24 11:20:13 +0200
#
#    improves ItemLabel handling

#
# get the path
#
getPath() {
  cd ..
  perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' $(pwd) $HOME
}

# how to get current directory name without full path
# https://stackoverflow.com/questions/1371261/get-current-directory-name-without-full-path-in-a-bash-script
project=${PWD##*/}

#path=$(getPath)
#path=$(echo "$path" | sed 's_Documents/workspace_source/java_')

giturl=$(git remote -v | grep fetch | cut -f2 | cut -f1 -d" ")
host=$(echo $giturl | cut -f1-3 -d"/")
path=$(echo $giturl | cut -f4- -d"/" | sed "s#/$project##")

case $host in
  git.bitplan.com:/srv/git) host=git://git.bitplan.com/srv/git
esac
# https://git-scm.com/docs/pretty-formats

# how to get Date in iso format with git
# https://stackoverflow.com/questions/7853332/how-to-change-git-log-date-formats
#git log --date=iso

git --no-pager log --reverse --pretty=format:{{commit'|'host=$host'|'path=${path}'|'project=${project}'|'subject=%s'|'name=%cn'|'date=%ci'|'hash=%h'|'storemode=subobject'|'viewmode=line}}