mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
fix diff of newfile when cwd in subdir (fixes #25)
This commit is contained in:
parent
e4b00adede
commit
53e4533c74
1 changed files with 24 additions and 1 deletions
|
|
@ -118,6 +118,7 @@ pub fn get_diff(repo_path: &str, p: String, stage: bool) -> FileDiff {
|
|||
scope_time!("get_diff");
|
||||
|
||||
let repo = utils::repo(repo_path);
|
||||
let repo_path = repo.path().parent().unwrap();
|
||||
|
||||
let (diff, mut opt) = get_diff_raw(&repo, &p, stage, false);
|
||||
|
||||
|
|
@ -168,7 +169,6 @@ pub fn get_diff(repo_path: &str, p: String, stage: bool) -> FileDiff {
|
|||
let delta: DiffDelta = diff.deltas().next().unwrap();
|
||||
|
||||
if delta.status() == Delta::Untracked {
|
||||
let repo_path = Path::new(repo_path);
|
||||
let newfile_path =
|
||||
repo_path.join(delta.new_file().path().unwrap());
|
||||
|
||||
|
|
@ -373,4 +373,27 @@ mod tests {
|
|||
|
||||
assert_eq!(res.hunks.len(), 2)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_diff_newfile_in_sub_dir_current_dir() {
|
||||
let file_path = Path::new("foo/foo.txt");
|
||||
let (_td, repo) = repo_init_empty();
|
||||
let root = repo.path().parent().unwrap();
|
||||
|
||||
let sub_path = root.join("foo/");
|
||||
|
||||
fs::create_dir_all(&sub_path).unwrap();
|
||||
File::create(&root.join(file_path))
|
||||
.unwrap()
|
||||
.write_all(b"test")
|
||||
.unwrap();
|
||||
|
||||
let diff = get_diff(
|
||||
sub_path.to_str().unwrap(),
|
||||
String::from(file_path.to_str().unwrap()),
|
||||
false,
|
||||
);
|
||||
|
||||
assert_eq!(diff.hunks[0].lines[1].content, "test");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue