Skip to content

patchable: Set the base branch as the git upstream branch #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ All notable changes to this project will be documented in this file.
- BREAKING: kcat: Stop building kcat image ([#1124]).
- containerdebug updated to 0.2.0 ([#1128])
- Build Hadoop as `stackable` and configure the Stackable Nexus build-repo for the `root` user ([#1133])
- patchable: The base branch is now configured as the git upstream branch ([#1131]).

### Fixed

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

## [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