We have a specific requirement in which we have to push all files which arrive for being committed to a certain branch.
We are planning to achieve this via git hooks specifically commit-msg hook.
While doing so what we do is we clone branch to temporary location (/tmp/) and then in git commit-msg hook, attempt to commit arrived files to certain branch.
But what happens now is we see all files as deleted in /tmp/.
Crude commit-msg script is as under:-
#!/bin/bash
#
#!/usr/bin/env bash
#git config credential.helper store
REPOSRC="https://<USER>:<PASS>@<REPO_URL>"
LOCALREPO="<LOCAL_REPO_DIR>"
echo "Pulling code to temporarry location";
cd /tmp && git clone "${REPOSRC}" || (cd "${LOCALREPO}"; git pull;)
#here when I navigate to /tmp/<LOCALREPO> all files are listed as DELETED
git diff --cached --name-status | while read st file; do
echo "file == $file and status == $st";
if [ "$st" == "A" ]; then
cd "${LOCALREPO}" && git add "$file" && git commit "$file" -m "$COMMIT_MSG" && git push origin "$branch"
else
cd "${LOCALREPO}" && git commit "$file" -m "$COMMIT_MSG" && git push origin "$branch"
fi
done
What can be the root cause for this?
EDIT:
GIT_INDEX_FILE shows path of index file from which commit was initiated and not /tmp/ path. Is there any way to change this variable? Also index file prints something like next-index-32419.lock. Regards