fix bug with a missing index write when doing rename of files

This commit is contained in:
Alexander Kjäll 2022-11-29 17:16:03 +01:00
parent b612633381
commit 2988a87dc2
No known key found for this signature in database
GPG Key ID: 1D108E6C07CBC406
3 changed files with 32 additions and 0 deletions

View File

@ -1206,6 +1206,7 @@ fn move_and_commit(
let mut index = repo.index()?;
index.remove_path(old_name)?;
index.add_path(new_name)?;
index.write()?;
let oid = index.write_tree()?;
let signature = repo.signature()?;
let parent_commit_res = find_last_commit(&repo);

View File

@ -922,6 +922,37 @@ fn rename_file_absolute_path() -> Result<()> {
Ok(())
}
#[test]
fn rename_file_git_index_clean() -> Result<()> {
let dir = UnpackedDir::new("rename_file_git_index_clean")?;
let mut config_location = dir.dir().to_path_buf();
config_location.push(".git");
config_location.push("config");
let mut config = git2::Config::open(&config_location)?;
config.set_str("user.name", "default")?;
config.set_str("user.email", "default@example.com")?;
config.set_str("commit.gpgsign", "false")?;
let mut store = PasswordStore::new(
"default",
&Some(dir.dir().to_path_buf()),
&None,
&Some(dir.dir().to_path_buf()),
&None,
&CryptoImpl::GpgMe,
&None,
)?;
store.reload_password_list()?;
store.rename_file("1/test", "2/test")?;
let repo = git2::Repository::open(dir.dir().to_path_buf())?;
assert!(repo.statuses(None)?.is_empty());
Ok(())
}
#[test]
fn decrypt_secret_empty_file() -> Result<()> {
let dir = tempfile::tempdir().unwrap();

Binary file not shown.