Skip to content

Commit

Permalink
Improve docker/bash.sh to handle git worktrees (#5970)
Browse files Browse the repository at this point in the history
* improve error code when git ls-files fails

* fix docker/bash to handle git worktrees
  • Loading branch information
areusch authored Jul 1, 2020
1 parent 36a0bf9 commit dd78036
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docker/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,22 @@ echo ""

echo "Running '${COMMAND[@]}' inside ${DOCKER_IMAGE_NAME}..."

# When running from a git worktree, also mount the original git dir.
EXTRA_MOUNTS=( )
if [ -f "${WORKSPACE}/.git" ]; then
git_dir=$(cd ${WORKSPACE} && git rev-parse --git-common-dir)
if [ "${git_dir}" != "${WORKSPACE}/.git" ]; then
EXTRA_MOUNTS=( "${EXTRA_MOUNTS[@]}" -v "${git_dir}:${git_dir}" )
fi
fi

# By default we cleanup - remove the container once it finish running (--rm)
# and share the PID namespace (--pid=host) so the process inside does not have
# pid 1 and SIGKILL is propagated to the process inside (jenkins can kill it).
${DOCKER_BINARY} run --rm --pid=host\
-v ${WORKSPACE}:/workspace \
-v ${SCRIPT_DIR}:/docker \
"${EXTRA_MOUNTS[@]}" \
-w /workspace \
-e "CI_BUILD_HOME=/workspace" \
-e "CI_BUILD_USER=$(id -u -n)" \
Expand Down
2 changes: 1 addition & 1 deletion tests/lint/check_file_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def main():
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out, _) = proc.communicate()
assert proc.returncode == 0
assert proc.returncode == 0, f'{" ".join(cmd)} errored: {out}'
res = out.decode("utf-8")
flist = res.split()
error_list = []
Expand Down

0 comments on commit dd78036

Please sign in to comment.