Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All notable changes to this project will be documented in this file.
- nifi: update patch allowing to bypass host header validation starting with NiFi 2.4.0 ([#1125]).
- BREAKING: kcat: Stop building kcat image ([#1124]).
- containerdebug updated to 0.2.0 ([#1128])
- patchable: The base branch is now configured as the git upstream branch ([#1131]).

### Fixed

Expand Down Expand Up @@ -148,6 +149,7 @@ All notable changes to this project will be documented in this file.
[#1125]: https://github.com/stackabletech/docker-images/pull/1125
[#1126]: https://github.com/stackabletech/docker-images/pull/1126
[#1128]: https://github.com/stackabletech/docker-images/pull/1128
[#1131]: https://github.com/stackabletech/docker-images/pull/1131

## [25.3.0] - 2025-03-21

Expand Down
1 change: 1 addition & 0 deletions rust/patchable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ fn main() -> Result<()> {
&ctx.pv.version,
&product_worktree_root,
&worktree_branch,
base_branch.as_deref(),
patched_commit,
)
.context(CheckoutProductWorktreeSnafu)?;
Expand Down
44 changes: 27 additions & 17 deletions rust/patchable/src/repo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::path::{self, Path, PathBuf};

use git2::{
FetchOptions, ObjectType, Oid, Repository, RepositoryInitOptions,
WorktreeAddOptions,
};
use git2::{FetchOptions, ObjectType, Oid, Repository, RepositoryInitOptions, WorktreeAddOptions};
use snafu::{ResultExt, Snafu};

use crate::{
Expand Down Expand Up @@ -215,6 +212,7 @@ pub fn ensure_worktree_is_at(
worktree_name: &str,
worktree_root: &Path,
branch: &str,
base_branch: Option<&str>,
commit: Oid,
) -> Result<()> {
tracing::info!("checking out worktree");
Expand Down Expand Up @@ -242,29 +240,41 @@ pub fn ensure_worktree_is_at(
commit: head_commit,
})?;
}
let branch = worktree
.branch(branch, &commit_obj, true)
.context(CreateWorktreeBranchSnafu {
let mut branch =
worktree
.branch(branch, &commit_obj, true)
.context(CreateWorktreeBranchSnafu {
repo: &worktree,
branch,
commit,
})?;
// Set the base branch as the patch branch's upstream, this helps some git GUIs (like magit)
// visualize the difference between upstream and our patchset.
if let Err(err) = branch.set_upstream(base_branch) {
tracing::warn!(
error = &err as &dyn std::error::Error,
branch.base = base_branch,
"failed to set upstream branch, ignoring..."
);
}
let branch_ref = branch.into_reference();
let commit = branch_ref
.peel(ObjectType::Commit)
.context(FindCommitSnafu {
repo: &worktree,
branch,
commit,
})?
.into_reference();
let commit = branch.peel(ObjectType::Commit).context(FindCommitSnafu {
repo: &worktree,
commit: &branch,
})?;
commit: &branch_ref,
})?;
worktree
.checkout_tree(&commit, None)
.context(CheckoutWorktreeSnafu {
worktree: &worktree,
commit: &commit,
})?;
worktree
.set_head_bytes(branch.name_bytes())
.set_head_bytes(branch_ref.name_bytes())
.context(UpdateWorktreeHeadSnafu {
worktree: &worktree,
target: &branch,
target: &branch_ref,
})?;
Ok(())
}
Expand Down