Skip to content

Commit

Permalink
Fix to consider multiple stashes on the same commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Aug 9, 2024
1 parent bd173a0 commit 3cd705e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,17 @@ fn merge_stashes_to_commits(commits: Vec<Commit>, stashes: Vec<Commit>) -> Vec<C
// Stash commit has multiple parent commits, but the first parent commit is the commit that the stash was created from.
// If the first parent commit is not found, the stash commit is ignored.
let mut ret = Vec::new();
let mut statsh_map: HashMap<CommitHash, Commit> = stashes
.into_iter()
.map(|commit| (commit.parent_commit_hashes[0].clone(), commit))
.collect();
let mut statsh_map: HashMap<CommitHash, Vec<Commit>> =
stashes.into_iter().fold(HashMap::new(), |mut acc, commit| {
let parent = commit.parent_commit_hashes[0].clone();
acc.entry(parent).or_default().push(commit);
acc
});
for commit in commits {
if let Some(stash) = statsh_map.remove(&commit.commit_hash) {
ret.push(stash);
if let Some(stashes) = statsh_map.remove(&commit.commit_hash) {
for stash in stashes {
ret.push(stash);
}
}
ret.push(commit);
}
Expand Down
Binary file modified tests/graph/stash_004_chrono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/graph/stash_004_topo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3cd705e

Please sign in to comment.