Skip to content

Commit 7ef9a8f

Browse files
committed
added ci_git_set_dir_safe.sh
1 parent 3a4f305 commit 7ef9a8f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

setup/ci_git_set_dir_safe.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: 2022-08-03 20:07:09 +0100 (Wed, 03 Aug 2022)
6+
#
7+
# https://github.com/HariSekhon/DevOps-Python-tools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12+
#
13+
# https://www.linkedin.com/in/HariSekhon
14+
#
15+
16+
# Necessary for some CI/CD systems like Azure DevOps Pipelines which have incorrect ownership on the git checkout dir triggering this error:
17+
#
18+
# fatal: detected dubious ownership in repository at '/code/sql'
19+
20+
# standalone script without lib dependency so it can be called directly from bootstrapped CI before submodules, since that is the exact problem that needs to be solved to allow CI/CD systems with incorrect ownership of the checkout directory to be able to checkout the necessary git submodules
21+
22+
set -euo pipefail
23+
[ -n "${DEBUG:-}" ] && set -x
24+
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25+
26+
dir="${1:-$srcdir/..}"
27+
28+
cd "$dir"
29+
30+
echo "Setting directory as safe: $PWD"
31+
git config --global --add safe.directory "$PWD"
32+
33+
while read -r submodule_dir; do
34+
dir="$PWD/$submodule_dir"
35+
echo "Setting directory as safe: $dir"
36+
git config --global --add safe.directory "$dir"
37+
done < <(git submodule | awk '{print $2}')
38+
39+
echo "Done"

0 commit comments

Comments
 (0)