Warning - read this only if you are willing to try following
# .zshrc / .bashrc
PATH_WITHOUT_PATCHING="$PATH"
ENABLE_PATCHING=1
PATCHED_GIT_PATH="$HOME/path/to/wherever/the/repo/was/cloned/patched-git/patched-bin"
if [[ $ENABLE_PATCHING && $ENABLE_PATCHING != 0 ]]; then
PATH="$PATCHED_GIT_PATH:$PATH"
fi
considering this script
Repository contains code/workaround to execute automatically custom pre-configured scripts when running git init
, or git clone
operations, see config.example.yml
This is (for obvious reasons) an experimental repository, and its content shouldn't be viewed by anyone
-
Setup dependencies, ensure both
jq
andsynopsis-parser
are in$PATH
-
Clone this repo
-
Run
make build
# Remain in the same directory - see steps below make -C patched-git build
-
Adjust the example project configuration - replace placeholders in config.example.yml
- Linux
cp patched-git/config/config.example.yml patched-git/config/config.yml # Replace relative paths with absolute sed -i "s#<<PWD>>#$PWD/patched-git#g" patched-git/config/config.yml sed -i "s#<<OS>>#$(uname | tr '[:upper:]' '[:lower:]')#g" patched-git/config/config.yml
- macOS
darwin
- difference insed
command
cp patched-git/config/config.example.yml patched-git/config/config.yml # Replace relative paths with absolute sed -i "" "s#<<PWD>>#$PWD/patched-git#g" patched-git/config/config.yml sed -i "" "s#<<OS>>#$(uname | tr '[:upper:]' '[:lower:]')#g" patched-git/config/config.yml
-
Configure a few environment variables
- Note - try this preferably in a session, rather than adding it to
.zshrc
/.bashrc
right away - Full config summary in source code - here
# Path override PATH_WITHOUT_PATCHING="$PATH" PATCHED_GIT_PATH="$PWD/patched-git/patched-bin" PATH="$PATCHED_GIT_PATH:$PATH" # "git-wrapper" specific env variable PATCHED_GIT_IS_ENABLED=true PATCHED_GIT_CONFIG="$PWD/patched-git/config/config.yml"
- For
darwin
(macOS) variables need to be exported in order to be passed into subprocess (todo - validate this)
export PATH_WITHOUT_PATCHING="$PATH" export PATCHED_GIT_PATH="$PWD/patched-git/patched-bin" export PATH="$PATCHED_GIT_PATH:$PATH" # "git-wrapper" specific env variable export PATCHED_GIT_IS_ENABLED=true export PATCHED_GIT_CONFIG="$PWD/patched-git/config/config.yml"
- Note - try this preferably in a session, rather than adding it to
-
Create a bare repository in same directory
mkdir test-bare git init --bare test-bare
-
Run a testing clone operation to see if preconfigured script is invoked
git clone ./test-bare ./test
-
You should see following prompt
-
If you press
y
you should get following outputHello from patched git-clone
make runtests