#!/bin/sh path=$1 token=$GIT_SYNC_COMMIT_TOKEN . ./git-sync-commit.config echo $path echo $token echo $state_branch # Implementation path_hash=$(eval "echo $path | base64") logs_cmd="cd $path && git log --author=$author --pretty='format:%n%H@%at'" logs=$(eval "$logs_cmd") if [ ! -f $path_hash ]; then touch $path_hash fi state=$(cat $path_hash) for commit in $logs; do if [[ ! $state =~ $commit ]]; then commit_hash=$(eval "echo $commit | grep -Eo '\b[0-9a-f]{40}'") commit_time_unformatted=$(eval "echo $commit | grep -Eo '@\d{10}'") commit_time="${commit_time_unformatted:1}" echo $commit >> $path_hash git add $path_hash commit_config=( "GIT_AUTHOR_NAME=$commit_author", "GIT_AUTHOR_EMAIL=$commit_email", "GIT_COMMITTER_NAME=$commit_author", "GIT_COMMITTER_EMAIL=$commit_email", "GIT_AUTHOR_DATE=$commit_time", "GIT_COMMITTER_DATE=$commit_time" ) eval "${commit_config[@]} git commit -q -m '$commit_hash'" echo "Added $commit_hash to state file" fi done git push "https://$token@github.com/$state_repo"