.git/refs/heads/master missing on test and deployment step

.git/refs/heads/master allow to determine the head commit of the current branch. npm publish use it to determine the git head and add to the published package. See https://github.com/npm/read-package-json/blob/master/read-json.js#L327

In the dependencies step .git/refs/heads/master is preset but it’s missing on all steps following dependencies.

See a reduced test case here: https://circleci.com/gh/vanduynslagerp/test-circleci/33

In order to publish properly with npm (after running the test) we need to have .git/refs/heads/master.

Why is circleCI removing this file ? IS there a way to preserve it?

Thanks

For information, as a workaround we can run this script first on the deployment step:
#!/usr/bin/env bash

set e+x
echo “Getting git refs”

git show-ref --head --heads | while IFS=’ ’ read -r hash name;
do
echo “ref $name hash hash" test ! -e "{GIT_DIR:-.git}/$name” && echo hash > "{GIT_DIR:-.git}/$name";
done

echo “All done”

Script from https://github.com/bahmutov/condition-circle/blob/master/refs.sh

Still it really seems a bug that Circle CI drops .git/refs/heads/master