Skip to content

Commit 64c794d

Browse files
authored
Merge pull request #11068 from Byron/fix2
Place local tracking branches at their remote tracking branch.
2 parents cdc1df6 + 5ac129b commit 64c794d

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

crates/but-workspace/src/branch/apply.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub(crate) mod function {
339339
!std::ptr::eq(branch_orig, branch);
340340
let (local_tracking_config_and_ref_info, commit_to_create_branch_at) =
341341
if incoming_branch_is_remote_tracking_without_local_tracking {
342-
setup_local_tracking_configuration(repo, branch, branch_orig, ws_ref_id)?
342+
setup_local_tracking_configuration(repo, branch, branch_orig)?
343343
.map(|(config, commit)| (Some(config), Some(commit)))
344344
.unwrap_or_default()
345345
} else {
@@ -784,26 +784,16 @@ pub(crate) mod function {
784784

785785
/// Setup `local_tracking_ref` to track `remote_tracking_ref` using the typical pattern, and prepare the configuration file
786786
/// so that it can replace `.git/config` of `repo` when written back, with everything the same but the branch configuration added.
787-
/// We also return the commit at which `local_tracking_ref` should be placed, which is assumed to not exist, and `repo` will be used
788-
/// for computing the merge-base with `ws_ref_id`, traditionally, without a graph, as forcing the graph here wouldn't buy us anything.
789-
/// Merge-base computations can still be done with `repo` IF the graph isn't up to date.
787+
/// We also return the commit at which `local_tracking_ref` should be placed, which is assumed to not exist.
790788
fn setup_local_tracking_configuration(
791789
repo: &gix::Repository,
792790
local_tracking_ref: &FullNameRef,
793791
remote_tracking_ref: &FullNameRef,
794-
ws_ref_id: gix::ObjectId,
795792
) -> anyhow::Result<Option<(gix::config::File<'static>, gix::ObjectId)>> {
796793
let remote_tracking_commit_id = repo
797794
.find_reference(remote_tracking_ref)?
798795
.peel_to_commit()?
799796
.id();
800-
let merge_base_commit_id = repo
801-
.merge_base(remote_tracking_commit_id, ws_ref_id)
802-
.unwrap_or_else(|_| {
803-
tracing::warn!("Couldn't find merge-base between remote tip {remote_tracking_commit_id} and workspace tip {ws_ref_id} - placing local tracking ref on remote tip");
804-
remote_tracking_commit_id
805-
})
806-
.detach();
807797

808798
// TODO(gix): Make config refreshes possible, and use the higher level API, and add a way
809799
// to only write back what changed and of course to add local sections more obviously.
@@ -826,7 +816,7 @@ pub(crate) mod function {
826816
Some(local_tracking_ref.as_bstr()),
827817
);
828818
}
829-
Ok(Some((config, merge_base_commit_id)))
819+
Ok(Some((config, remote_tracking_commit_id.into())))
830820
}
831821

832822
fn add_branch_as_stack_forcefully(

crates/but-workspace/tests/workspace/branch/apply_unapply_commit_uncommit.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,23 @@ fn main_with_advanced_remote_tracking_branch() -> anyhow::Result<()> {
178178
let ws = graph.to_workspace()?;
179179
// both branches, main and feature, are available in the newly created workspace ref.
180180
insta::assert_snapshot!(graph_workspace(&ws), @r"
181-
📕🏘️⚠️:0:gitbutler/workspace <> ✓! on 3183e43
182-
├── ≡📙:3:feature on 3183e43 {2ec}
183-
│ └── 📙:3:feature
184-
└── ≡📙:2:main on 3183e43 {1a5}
185-
└── 📙:2:main
181+
📕🏘️:0:gitbutler/workspace <> ✓! on 3183e43
182+
├── ≡📙:2:feature on 3183e43 {2ec}
183+
│ └── 📙:2:feature
184+
│ └── ·6b40b15 (🏘️)
185+
└── ≡📙:3:main on 3183e43 {1a5}
186+
└── 📙:3:main
186187
");
187188

188189
// the new local tracking ref actually exists, and is in the right spot.
189190
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
190-
* 6b40b15 (origin/feature) without-local-tracking
191+
* e00cf08 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
192+
|\
193+
| * 6b40b15 (origin/feature, feature) without-local-tracking
194+
|/
191195
| * 552e7dc (origin/main) only-on-remote
192196
|/
193-
* 3183e43 (HEAD -> gitbutler/workspace, main, feature) M1
197+
* 3183e43 (main) M1
194198
");
195199

196200
let config = repo.local_common_config_for_editing()?;

0 commit comments

Comments
 (0)