I have a build process for producing RPMs. The team uses rpm release numbers to help track version information. They look like <program_name>-<version>-<rel_num>.<os_type>.<arch>.rpm
; where the following are true:
- version is the semantic version pattern MAJOR.MINOR.PATCH
- rel_num is simply an every increasing integer stored in revision control to help make it unique
- os_type is el7 for Enterprise Linux 7
- arch as expected x86_64 or what have you
The project I'm working on has its source stored in git. This release number process for the RPMs is inherited from subversion (where most projects our team supports reside).
In order to maintain uniqueness, I've made a branch named rpm
for the project which has a unique directory containing a file named rpm_build_num
. The idea is that this file is only to reside on the rpm branch. During the make
process, a BASH script is called to checkout the rpm branch, making a new branch based upon origin/rpm
if it doesn't exist: increment the build number and then push it back to the remote. Once this is completed, the script restores the branch before exiting. In brief BASH
storedBranch=$(git branch | awk -e '/^\* / {print $2}')
git branch | grep -q rpm
if [[ ${PIPESTATUS[1]} != 0 ]]; then
git checkout -b rpm origin/rpm
else
git checkout rpm
fi
# fetch and merge origin/rpm if needed
cd path/to/dir
echo (( $(cat rpm_build_num) + 1 )) > rpm_build_num
git add rpm_buid_num
git commit -m "incrementing the build number"
git push origin rpm
cd -
git checkout ${storedBranch}
The problem is that, for reasons I don't yet understand, sometimes the make process, started from the shell prompt, gets lost with respect to which branch it's actually using. I'm being very careful in every stage of this process to start various things, like this script, from directories that exist in all branches. Yet, I still see this at times:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
The above error prints out 4 or 5 times while make is processing a couple of lines of comments. I've had no luck fixing this with my few attempts. My internet searches have yielded many results with stuff like, "Working with branches," or, "Switching branches," but nothing that's exactly related to this. Since I cannot update a file on a different branch, commit and push it without actually changing to that branch (I did find the answer to that question), what options might I have?