I've got a work environment in which I frequently build binaries and then kick off long-running processes using that binary. While these are running, I would like to switch to another git branch and do some work there, and potentially build some new binaries that wouldn't overwrite the ones currently running.
Right now, the build and run scripts use a $OUT_DIR
env variable to determine the output dir for binaries. Ideally, I would like to have $OUT_DIR
be branch-specific to avoid the above mentioned problem of builds overwriting each other.
At first, this seemed like a simple job for the post-checkout hook -- set OUT_DIR
to be OUT_DIR_BASE + "/" + current branch
... except post-checkout hook runs in a child shell so it can't set parent env variables.
Are there any clever ways to get around this?
Some ideas I've considered:
export OUT_DIR...
" command to a file and make the
user source it -- that's annoying and people will forget to do it.OUT_DIR
into an .rc file and have build/run scripts
pick it up from there, but that requires changes to the build
environment, and user experience gets a bit worse (i.e. you can't do "cd $OUT_DIR
" to get into the output directory... git checkout
' that would open a
new shell with OUT_DIR
set appropriately... but that's "leaking"
shells where over time I'd have quite a large number running.None of these seem very nice for what feels like should be an easy solution.
I could print the branch name into a file and have build/run scripts pick it up from there
That remains the way to explore, even though it involve modifying the build script.
But getting the current branch name for a repo isn't hard:
git -C /path/to/repo rev-parse --abbrev-ref HEAD
So you wouldn't need to write the name of the current branch: the build script could get it directly from the repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With