Using git-secret with git pre-commit not working

989 Views Asked by At

When setting up pre-commit hook to call git secret hide in order to encrypt secret files on running commit to commit one or more changed files, the changed files are committed as expected but I am left with two new changed files which are not staged or committed .gitsecret/paths/mapping.cfg and src/tokens.ts.secret with tokens file being my secret file. The secret file appears to be the new encrypted file but issue is that it is not being staged or committed. I am unsure of what my pre-commit file should look like, should it manually add/commit files - I wouldn't think so.

My pre-commit file looks like:

#!/bin/sh
export PATH=/usr/local/bin:$PATH
echo "path $PATH"
git secret hide

Expected result is that these two files are staged and committed together with my commit.

1

There are 1 best solutions below

0
On

Solution was to add the changed files after call secret hide in pre-commit file. This is what worked for me.

#!/bin/sh
export PATH=/usr/local/bin:$PATH
echo "encrypting files"
git secret hide
git add .gitsecret/paths/mapping.cfg
git add src/*.secret