mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
add test for untracked files in stash bug (#130)
This commit is contained in:
parent
dd7880d650
commit
19db19b010
3 changed files with 32 additions and 5 deletions
|
|
@ -71,7 +71,11 @@ pub(crate) fn get_commit_diff(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::get_commit_files;
|
use super::get_commit_files;
|
||||||
use crate::{
|
use crate::{
|
||||||
sync::{commit, stage_add_file, tests::repo_init, CommitId},
|
error::Result,
|
||||||
|
sync::{
|
||||||
|
commit, stage_add_file, stash_save, tests::repo_init,
|
||||||
|
CommitId,
|
||||||
|
},
|
||||||
StatusItemType,
|
StatusItemType,
|
||||||
};
|
};
|
||||||
use std::{fs::File, io::Write, path::Path};
|
use std::{fs::File, io::Write, path::Path};
|
||||||
|
|
@ -98,4 +102,27 @@ mod tests {
|
||||||
assert_eq!(diff.len(), 1);
|
assert_eq!(diff.len(), 1);
|
||||||
assert_eq!(diff[0].status, StatusItemType::New);
|
assert_eq!(diff[0].status, StatusItemType::New);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_stashed_untracked() -> Result<()> {
|
||||||
|
let file_path = Path::new("file1.txt");
|
||||||
|
let (_td, repo) = repo_init().unwrap();
|
||||||
|
let root = repo.path().parent().unwrap();
|
||||||
|
let repo_path = root.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
|
File::create(&root.join(file_path))?
|
||||||
|
.write_all(b"test file1 content")?;
|
||||||
|
|
||||||
|
let id = stash_save(repo_path, None, true, false)?;
|
||||||
|
|
||||||
|
//TODO: https://github.com/extrawurst/gitui/issues/130
|
||||||
|
// `get_commit_diff` actually needs to merge the regular diff
|
||||||
|
// and a third parent diff containing the untracked files
|
||||||
|
let _diff = get_commit_files(repo_path, id)?;
|
||||||
|
|
||||||
|
// assert_eq!(diff.len(), 1);
|
||||||
|
// assert_eq!(diff[0].status, StatusItemType::New);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ pub fn stash_save(
|
||||||
message: Option<&str>,
|
message: Option<&str>,
|
||||||
include_untracked: bool,
|
include_untracked: bool,
|
||||||
keep_index: bool,
|
keep_index: bool,
|
||||||
) -> Result<()> {
|
) -> Result<CommitId> {
|
||||||
scope_time!("stash_save");
|
scope_time!("stash_save");
|
||||||
|
|
||||||
let mut repo = repo(repo_path)?;
|
let mut repo = repo(repo_path)?;
|
||||||
|
|
@ -90,9 +90,9 @@ pub fn stash_save(
|
||||||
options.insert(StashFlags::KEEP_INDEX)
|
options.insert(StashFlags::KEEP_INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.stash_save2(&sig, message, Some(options))?;
|
let id = repo.stash_save2(&sig, message, Some(options))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(CommitId::new(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ impl Component for StashMsgComponent {
|
||||||
self.options.stash_untracked,
|
self.options.stash_untracked,
|
||||||
self.options.keep_index,
|
self.options.keep_index,
|
||||||
) {
|
) {
|
||||||
Ok(()) => {
|
Ok(_) => {
|
||||||
self.input.clear();
|
self.input.clear();
|
||||||
self.hide();
|
self.hide();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue