[GSoC] [RFC] Proposal: Teach git stash to handle unmerged index entries.
- Date: Tue, 9 Apr 2019 21:09:25 +0530
- From: Kapil Jain <jkapil.cs@xxxxxxxxx>
- Subject: [GSoC] [RFC] Proposal: Teach git stash to handle unmerged index entries.
Plan to implement the project.
Teach git stash to handle unmerged index entries.
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.
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`.
Idea Execution Plan: Divided into 2 parts.
Part 1: Store the unmerged index entries this part will work with `git
stash.sh: file would be changed to accommodate the below implementation.
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.
cache-tree.c: study and implement a slightly modified version of the
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.
write-tree.c: some possible changes will go here, so as to use the
modified version of write_index_as_tree() function.
use git-commit-tree to commit the written tree and store the hash in
some file say `stash_conflicting_merge`
Write tests for all implementation till this point.
Part 2: Retrieve the tree hash and regenerate the state of repository
as it was earlier.
Modify implementation of `git stash apply` for regenerating the committed tree.