Skip to content

Instantly share code, notes, and snippets.

@bradley-pp
Created March 28, 2025 15:21
Show Gist options
  • Select an option

  • Save bradley-pp/2010de97caddb179095c23a8565c3f32 to your computer and use it in GitHub Desktop.

Select an option

Save bradley-pp/2010de97caddb179095c23a8565c3f32 to your computer and use it in GitHub Desktop.
#!/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"
author="example@users.noreply.github.com" # Email of original committer
state_repo="example/example" # Repo to save state to
state_branch="main" # Branch to save state to
commit_author="example" # Name of new comitter
commit_email="example@users.noreply.github.com" # Email of new comitter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment