Git rebase --exec cannot run git commands affecting other repos
- From
- Samir Benmendil <me@rmz.io>
- Date
- Jan 10, 2019, 16:19 UTC
- Message-ID
- <20190110161904.23fwbrgg7blyx3nj@uh-nuc001>
It is impossible to run git commands affecting a different repo from within a `git rebase --exec` because in that environment the `GIT_DIR` and `GIT_WORK_TREE` variables are set and inherited by any commands run as part of `git rebase --exec`.
A minimal reproduction is shown below:
git init
touch file
git add file
git commit -m"Commit"
git rebase --root --exec="git clone . subrepo"It is a bit convoluted for the sake of being self contained. But any git command in `--exec` acting on a different repo than the one being rebased will fail. See my ticket on CMake [0] for a more real usecase.
As mentioned in the other ticket, unsetting these variables will work around the issue.
git rebase --root --exec="env -u GIT_DIR -u GIT_WORK_TREE git clone . subrepo"
[0] https://gitlab.kitware.com/cmake/cmake/issues/18778
Regards