Skip to content

Commit

Permalink
Merge branch 'feature/docker_git_safe_dirs_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
feat(docker): allow to add dirs into git's safe.directory (v5.1)

See merge request espressif/esp-idf!27560
  • Loading branch information
dobairoland committed Dec 1, 2023
2 parents 9a05c94 + 99f9dd4 commit b5289ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/en/api-guides/tools/idf-docker-image.rst
Expand Up @@ -60,6 +60,10 @@ The above command explained:
- ``espressif/idf``: uses Docker image ``espressif/idf`` with tag ``latest`` (implicitly added by Docker when no tag is specified)
- ``idf.py build``: runs this command inside the container

.. note::

When the mounted directory, ``/project``, contains a git repository owned by a different user (``UID``) than the one running the Docker container, git commands executed within ``/project`` might fail, displaying an error message ``fatal: detected dubious ownership in repository at '/project'``. To resolve this issue, you can designate the ``/project`` directory as safe by setting the IDF_GIT_SAFE_DIR environment variable during the Docker container startup. For instance, you can achieve this by including ``-e IDF_GIT_SAFE_DIR='/project'`` as a parameter. Additionally, multiple directories can be specified by using a ``:`` separator. To entirely disable this git security check, ``*`` can be used.

To build with a specific Docker image tag, specify it as ``espressif/idf:TAG``, for example::

docker run --rm -v $PWD:/project -w /project espressif/idf:release-v4.4 idf.py build
Expand Down
14 changes: 14 additions & 0 deletions tools/docker/entrypoint.sh
@@ -1,6 +1,20 @@
#!/usr/bin/env bash
set -e

# IDF_GIT_SAFE_DIR has the same format as system PATH environment variable.
# All path specified in IDF_GIT_SAFE_DIR will be added to user's
# global git config as safe.directory paths. For more information
# see git-config manual page.
if [ -n "${IDF_GIT_SAFE_DIR+x}" ]
then
echo "Adding following directories into git's safe.directory"
echo "$IDF_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir
do
git config --global --add safe.directory "$dir"
echo " $dir"
done
fi

. $IDF_PATH/export.sh

exec "$@"

0 comments on commit b5289ed

Please sign in to comment.