Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git: add dummy conflict to index if necessary
We want to prevent the user from committing with `git commit` whenever the working copy commit still contains conflicts, since that would result in conflict markers being committed as text. Git will prevent the user from committing if there are conflicts present in the index, so there are two main cases where this can happen: 1. If the working copy commit contains conflicted files which weren't conflicted in the merged parent tree, then those files won't appear as conflicts in the index (since the index is based on the parents). 2. If there are conflicts with more than 2 sides, those conflicts cannot be represented in the index (since Git only allows 2-sided conflicts in the index). To detect these two cases, we start with a set of all paths which are conflicted in the working copy commit, and whenever we add a conflict to the index, we remove that path from the set. If there are any paths remaining in the set after populating the index, that means that there is a conflicted file in the working copy which is not present in the index. If this happens, we add a ".jj-do-not-resolve-this-conflict" file as a dummy conflict in the index. This will prevent the user from accidentally committing without resolving the conflicts first. This approach means that in the most common cases (resolving merge conflicts after running `jj new A B` or resolving rebase conflicts by running `jj new` on the first conflicted commit), it won't be necessary to add any dummy conflict to the index since in these cases, the index already contains all of the conflicts.
- Loading branch information