mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
fix crash diffing stash created on cmd line (closes #178)
This commit is contained in:
parent
59d93d7c23
commit
02bd22d3b3
3 changed files with 40 additions and 11 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
if let Ok(untracked_commit) = commit.parent_id(2) {
|
||||
let untracked_diff = get_commit_diff(
|
||||
repo,
|
||||
CommitId::new(untracked_commit),
|
||||
pathspec,
|
||||
)?;
|
||||
|
||||
let untracked_diff = get_commit_diff(
|
||||
repo,
|
||||
CommitId::new(untracked_commit),
|
||||
pathspec,
|
||||
)?;
|
||||
|
||||
diff.merge(&untracked_diff)?;
|
||||
diff.merge(&untracked_diff)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(diff)
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue