Skip to content

Draft: Fix Windows escaping issues with git submodule pathspecs

Stan Hu requested to merge sh-fix-git-submodules-escaping into main

What does this MR do?

!4278 (merged) changed the sequence of git submodule from:

git submodule init
git submodule sync -- :(exclude)gitlab-grack simplegit
git submodule foreach "git clean -ffdx"
git submodule foreach "git reset --hard"
git submodule update --init -- :(exclude)gitlab-grack simplegit
git submodule foreach "git clean -ffdx"
git submodule foreach "git lfs pull"

To this:

git submodule init
git submodule sync -- :(exclude)gitlab-grack simplegit
git submodule foreach "git clean -ffdx"
git submodule foreach "git reset --hard"
git submodule sync -- :(exclude)gitlab-grack simplegit
git submodule update --init -- :(exclude)gitlab-grack simplegit
git submodule foreach "git reset --hard"
git submodule foreach "git clean -ffdx"
git submodule foreach "git lfs pull"

The Windows CMD shell appears to have difficulty interpreting the :(exclude) part of the pathspec. To avoid these issues, surround each pathspec with double quotes:

git submodule sync -- ":(exclude)gitlab-grack" "simplegit"

We can do this by using CmdWriter.CommandArgExpand instead of CmdWriter.Command. In Windows, ( and ) could be command blocks, so Command does not escape them. CommandArgExpand will surround each Git argument with quotes, so this works across all shells.

Relates to #36694 (closed)

Edited by Stan Hu

Merge request reports