Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion icechunk/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,13 @@ impl Session {
// Icechunk 1 doesn't support amend
self.asset_manager.fail_unless_spec_at_least(SpecVersionBin::V2dot0)?;

// Cannot amend the initial commit (which has no parent and no transaction log)
let (repo_info, _) = self.asset_manager.fetch_repo_info().await?;
let current_snapshot_info = repo_info.find_snapshot(self.snapshot_id())?;
if current_snapshot_info.is_initial() {
return Err(SessionErrorKind::NoAmendForInitialCommit.into());
}

self._commit(message, properties, false, CommitMethod::Amend).await
}

Expand Down Expand Up @@ -2606,7 +2613,7 @@ async fn do_commit_v2(
(CommitMethod::NewCommit, _) => parent_snapshot_id.clone(),
(CommitMethod::Amend, Some(parent_id)) => parent_id,
(CommitMethod::Amend, None) => {
return Err(RepositoryErrorKind::NoAmendForInitialCommit.into());
unreachable!("amend() checks for initial commit before calling _commit")
}
};

Expand Down Expand Up @@ -4184,6 +4191,15 @@ mod tests {
#[tokio_test]
async fn test_amend() -> Result<(), Box<dyn Error>> {
let repo = create_memory_store_repository().await;

// Test that amending the initial commit fails
let mut session = repo.writable_session("main").await?;
session.add_group(Path::root(), Bytes::copy_from_slice(b"")).await?;
let amend_result = session.amend("cannot amend initial commit", None).await;
assert!(amend_result.is_err());
assert!(amend_result.unwrap_err().to_string().contains("first commit"));

// Now make a proper first commit
let mut session = repo.writable_session("main").await?;
session.add_group(Path::root(), Bytes::copy_from_slice(b"")).await?;
session.commit("make root", None).await?;
Expand Down
Loading