Skip to content

Commit

Permalink
fix crash diffing stash created on cmd line (closes #178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Jul 7, 2020
1 parent 59d93d7 commit 02bd22d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- switch deprecated transitive dependency `net2`->`socket2` [in `crossterm`->`mio`] ([#66](https://github.com/extrawurst/gitui/issues/66))
- crash diffing stash created on command line ([#178](https://github.com/extrawurst/gitui/issues/178))

## [0.8.0] - 2020-07-06

Expand Down
18 changes: 9 additions & 9 deletions asyncgit/src/sync/commit_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ pub(crate) fn get_commit_diff(
repo.path().to_str().expect("repo path utf8 err"),
&id,
)? {
let untracked_commit = commit.parent_id(2)?;

let untracked_diff = get_commit_diff(
repo,
CommitId::new(untracked_commit),
pathspec,
)?;

diff.merge(&untracked_diff)?;
if let Ok(untracked_commit) = commit.parent_id(2) {
let untracked_diff = get_commit_diff(
repo,
CommitId::new(untracked_commit),
pathspec,
)?;

diff.merge(&untracked_diff)?;
}
}

Ok(diff)
Expand Down
34 changes: 31 additions & 3 deletions asyncgit/src/sync/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ pub fn stash_save(
mod tests {
use super::*;
use crate::sync::{
get_commits_info,
tests::{get_statuses, repo_init},
commit, get_commit_files, get_commits_info, stage_add_file,
tests::{debug_cmd_print, get_statuses, repo_init},
};
use std::{fs::File, io::Write};
use std::{fs::File, io::Write, path::Path};

#[test]
fn test_smoke() {
Expand Down Expand Up @@ -183,4 +183,32 @@ mod tests {

Ok(())
}

#[test]
fn test_stash_without_2nd_parent() -> Result<()> {
let file_path1 = Path::new("file1.txt");
let (_td, repo) = repo_init()?;
let root = repo.path().parent().unwrap();
let repo_path = root.as_os_str().to_str().unwrap();

File::create(&root.join(file_path1))?.write_all(b"test")?;
stage_add_file(repo_path, file_path1)?;
commit(repo_path, "c1")?;

File::create(&root.join(file_path1))?
.write_all(b"modified")?;

//NOTE: apparently `libgit2` works differently to git stash in
//always creating the third parent for untracked files while the
//cli skips that step when no new files exist
debug_cmd_print(repo_path, "git stash");

let stash = get_stashes(repo_path)?[0];

let diff = get_commit_files(repo_path, stash)?;

assert_eq!(diff.len(), 1);

Ok(())
}
}

0 comments on commit 02bd22d

Please sign in to comment.