diff --git a/CHANGELOG.md b/CHANGELOG.md index f1526a646..48faf11a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/rust/patchable/src/main.rs b/rust/patchable/src/main.rs index 10b5ae988..1a5548538 100644 --- a/rust/patchable/src/main.rs +++ b/rust/patchable/src/main.rs @@ -426,6 +426,7 @@ fn main() -> Result<()> { &ctx.pv.version, &product_worktree_root, &worktree_branch, + base_branch.as_deref(), patched_commit, ) .context(CheckoutProductWorktreeSnafu)?; diff --git a/rust/patchable/src/repo.rs b/rust/patchable/src/repo.rs index 962dc03d9..26e31cdac 100644 --- a/rust/patchable/src/repo.rs +++ b/rust/patchable/src/repo.rs @@ -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::{ @@ -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"); @@ -242,18 +240,30 @@ 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 { @@ -261,10 +271,10 @@ pub fn ensure_worktree_is_at( 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(()) }