[GSoC] [RFC] Proposal: Teach git stash to handle unmerged index entries.
- From
- Kapil Jain <jkapil.cs@gmail.com>
- Date
- Apr 9, 2019, 15:39 UTC
- Message-ID
- <CAMknYEMh=CN6GGRPD_fkafHy84e49JY5dK2dAgX6Z7542dJ-Uw@mail.gmail.com>
Plan to implement the project.
Objective: Teach git stash to handle unmerged index entries.
Description: When the index is unmerged, git stash refuses to do anything. That is unnecessary, though, as it could easily craft e.g. an octopus merge of the various stages. A subsequent git stash apply can detect that octopus and re-generate the unmerged index.
Implementation Idea: Performing an octopus merge of all `stage n` (n>0) unmerged index entries, could solve the problem, but
What if there are conflicts in merging ? In this case, we would store(commit) the conflicted state, so they can be regenerated when git stash is applied.
How to store the conflicted files ? create a tree from the merge using `git-write-tree` and then commit that tree using `git-commit-tree`.
Relevant Discussions: https://colabti.org/irclogger/irclogger_log/git-devel?date=2019-04-05#l92 https://colabti.org/irclogger/irclogger_log/git-devel?date=2019-04-09#l47
Idea Execution Plan: Divided into 2 parts.
Part 1: Store the unmerged index entries this part will work with `git stash push`
stash.sh: file would be changed to accommodate the below implementation.
Step 1: Extract all the unmerged entries from index file and store them in a temporary index file.
read-cache.c: this file is responsible for reading index file, probably this implementation will end up in this file.
Step 2: cache-tree.c: study and implement a slightly modified version of the function `write_index_as_tree()`
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
this function is responsible for writing tree from index file. Currently in this function, the index must be in a fully merged state, and we are dealing with its exact opposite. So a version to write tree for unmerged index entries will be implemented.
Step 3: write-tree.c: some possible changes will go here, so as to use the modified version of write_index_as_tree() function.
Step 4: use git-commit-tree to commit the written tree and store the hash in some file say `stash_conflicting_merge`
Step 5: Write tests for all implementation till this point.
Part 2: Retrieve the tree hash and regenerate the state of repository as it was earlier.
Step 6: Modify implementation of `git stash apply` for regenerating the committed tree.
Step 7: Write tests.