Skip to content

Commit 864bca2

Browse files
committed
Add reword_safe test
1 parent bae1782 commit 864bca2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

asyncgit/src/sync/rebase.rs

+45
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,48 @@ fn reword(
141141
// Repo is not on a branch, possibly detached head
142142
Err(Error::NoBranch)
143143
}
144+
145+
#[cfg(test)]
146+
mod tests {
147+
use super::*;
148+
use crate::sync::{
149+
commit, stage_add_file, tests::repo_init_empty,
150+
};
151+
use std::{fs::File, io::Write, path::Path};
152+
153+
#[test]
154+
fn test_reword() -> Result<()> {
155+
let file_path = Path::new("foo");
156+
let (_td, repo) = repo_init_empty().unwrap();
157+
let root = repo.path().parent().unwrap();
158+
let repo_path = root.as_os_str().to_str().unwrap();
159+
160+
File::create(&root.join(file_path))?.write_all(b"a")?;
161+
stage_add_file(repo_path, file_path).unwrap();
162+
commit(repo_path, "commit1").unwrap();
163+
File::create(&root.join(file_path))?.write_all(b"ab")?;
164+
stage_add_file(repo_path, file_path).unwrap();
165+
let oid2 = commit(repo_path, "commit2").unwrap();
166+
167+
let branch =
168+
repo.branches(None).unwrap().next().unwrap().unwrap().0;
169+
let branch_ref = branch.get();
170+
let commit_ref = branch_ref.peel_to_commit().unwrap();
171+
let message = commit_ref.message().unwrap();
172+
173+
assert_eq!(message, "commit2");
174+
175+
reword_safe(repo_path, oid2.into(), "NewCommitMessage")
176+
.unwrap();
177+
178+
// Need to get the branch again as top oid has changed
179+
let branch =
180+
repo.branches(None).unwrap().next().unwrap().unwrap().0;
181+
let branch_ref = branch.get();
182+
let commit_ref_new = branch_ref.peel_to_commit().unwrap();
183+
let message_new = commit_ref_new.message().unwrap();
184+
assert_eq!(message_new, "NewCommitMessage");
185+
186+
Ok(())
187+
}
188+
}

0 commit comments

Comments
 (0)