Skip to content

Commit c7d0c7a

Browse files
authored
Merge pull request #10699 from gitbutlerapp/fix-integration-detection
fix: Integration detection
2 parents ca01a84 + c8ba95e commit c7d0c7a

File tree

8 files changed

+89
-20
lines changed

8 files changed

+89
-20
lines changed

crates/gitbutler-branch-actions/src/upstream_integration.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ fn get_stack_status(
272272
stack_id: Option<StackId>,
273273
ctx: &CommandContext,
274274
) -> Result<StackStatus> {
275-
let mut unintegrated_branch_found = false;
276-
277275
let mut last_head: git2::Oid = gix_to_git2_oid(new_target_commit_id);
278276

279277
let mut branch_statuses: Vec<NameAndStatus> = vec![];
@@ -293,24 +291,18 @@ fn get_stack_status(
293291
continue;
294292
};
295293

296-
// If an integrated branch has been found, there is no need to bother
297-
// with subsequent branches.
298-
if !unintegrated_branch_found
299-
&& matches!(
300-
branch_head.state,
301-
but_workspace::ui::CommitState::Integrated
302-
)
303-
{
294+
// Check if the branch in question has already been integrated
295+
if matches!(
296+
branch_head.state,
297+
but_workspace::ui::CommitState::Integrated
298+
) {
304299
branch_statuses.push(NameAndStatus {
305300
name: branch.name.to_string(),
306301
status: BranchStatus::Integrated,
307302
});
308303

309304
continue;
310-
} else {
311-
unintegrated_branch_found = true;
312305
}
313-
314306
// Rebase the commits and see if any conflict
315307
// Rebasing is preferable to merging, as not everything that is
316308
// mergable is rebasable.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "GIT CONFIG $GIT_CONFIG_GLOBAL"
4+
echo "DATA DIR $GITBUTLER_CLI_DATA_DIR"
5+
echo "BUT_TESTING $BUT_TESTING"
6+
echo "BRANCH DESTINATION: $1"
7+
echo "BRANCH TO MOVE: $2"
8+
echo "DIRECTORY: $3"
9+
10+
# Apply remote branch to the workspace.
11+
pushd "$3"
12+
$BUT_TESTING -j move-branch $1 $2
13+
popd

e2e/playwright/scripts/project-with-remote-branches.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ git commit -am "branch2: second commit"
3333
git checkout master
3434
popd
3535

36+
# Create branch3
37+
pushd remote-project
38+
git checkout -b branch3
39+
echo "branch3 commit 1" >> b_file
40+
git add b_file
41+
git commit -am "branch3: first commit"
42+
git checkout master
43+
popd
44+
3645
# Clone the remote into a folder and add the project to the application.
3746
git clone remote-project local-clone
3847
pushd local-clone

e2e/playwright/tests/branches.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('should be able to apply a remote branch', async ({ page, context }, testIn
4141
await expect(header).toContainText('origin/master');
4242

4343
const branchListCards = getByTestId(page, 'branch-list-card');
44-
await expect(branchListCards).toHaveCount(2);
44+
await expect(branchListCards).toHaveCount(3);
4545

4646
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
4747
await expect(firstBranchCard).toBeVisible();
@@ -88,7 +88,7 @@ test('should be able to apply a remote branch and integrate the remote changes -
8888
await expect(header).toContainText('origin/master');
8989

9090
const branchListCards = getByTestId(page, 'branch-list-card');
91-
await expect(branchListCards).toHaveCount(2);
91+
await expect(branchListCards).toHaveCount(3);
9292

9393
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
9494
await expect(firstBranchCard).toBeVisible();
@@ -345,7 +345,7 @@ test('should be able gracefully handle adding a branch that is ahead of our targ
345345
await expect(header).toContainText('origin/master');
346346

347347
const branchListCards = getByTestId(page, 'branch-list-card');
348-
await expect(branchListCards).toHaveCount(2);
348+
await expect(branchListCards).toHaveCount(3);
349349

350350
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
351351
await expect(firstBranchCard).toBeVisible();
@@ -399,7 +399,7 @@ test('should be able gracefully handle adding a branch that is behind of our tar
399399
await expect(header).toContainText('origin/master');
400400

401401
const branchListCards = getByTestId(page, 'branch-list-card');
402-
await expect(branchListCards).toHaveCount(2);
402+
await expect(branchListCards).toHaveCount(3);
403403

404404
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
405405
await expect(firstBranchCard).toBeVisible();

e2e/playwright/tests/commitActions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('should be able to amend a file to a commit', async ({ page, context }, tes
3434
await expect(header).toContainText('origin/master');
3535

3636
const branchListCards = getByTestId(page, 'branch-list-card');
37-
await expect(branchListCards).toHaveCount(2);
37+
await expect(branchListCards).toHaveCount(3);
3838

3939
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
4040
await expect(firstBranchCard).toBeVisible();

e2e/playwright/tests/upstreamIntegration.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,56 @@ test('should handle the update of workspace with integrated branch gracefully',
7979
await waitForTestIdToNotExist(page, 'stack');
8080
});
8181

82+
test('should handle the update of workspace with integrated parent branch in stack gracefully', async ({
83+
page,
84+
context
85+
}, testInfo) => {
86+
const workdir = testInfo.outputPath('workdir');
87+
const configdir = testInfo.outputPath('config');
88+
gitbutler = await startGitButler(workdir, configdir, context);
89+
90+
await gitbutler.runScript('project-with-remote-branches.sh');
91+
// Apply branch1
92+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
93+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch3', 'local-clone']);
94+
await gitbutler.runScript('move-branch.sh', ['branch3', 'branch1', 'local-clone']);
95+
96+
await page.goto('/');
97+
98+
// Should load the workspace
99+
await waitForTestId(page, 'workspace-view');
100+
101+
// There should be one stack applied
102+
let stacks = getByTestId(page, 'stack');
103+
await expect(stacks).toHaveCount(1);
104+
let branchCards = getByTestId(page, 'branch-card');
105+
await expect(branchCards).toHaveCount(2);
106+
107+
// Branch one was merged in the forge
108+
await gitbutler.runScript('merge-upstream-branch-to-base.sh', ['branch1']);
109+
110+
// Click the sync button
111+
await clickByTestId(page, 'sync-button');
112+
113+
// Update the workspace
114+
await clickByTestId(page, 'integrate-upstream-commits-button');
115+
116+
// The staus of the branch1 should be "Integrated"
117+
const branch1Status = page.locator('[data-integration-row-branch-name="branch1"]').first();
118+
await branch1Status.waitFor();
119+
const statusBadge = branch1Status.getByTestId('integrate-upstream-series-row-status-badge');
120+
await statusBadge.waitFor();
121+
await expect(statusBadge).toHaveText('Integrated');
122+
123+
await clickByTestId(page, 'integrate-upstream-action-button');
124+
125+
// There should be one stack left with one branch
126+
stacks = getByTestId(page, 'stack');
127+
await expect(stacks).toHaveCount(1);
128+
branchCards = getByTestId(page, 'branch-card');
129+
await expect(branchCards).toHaveCount(1);
130+
});
131+
82132
test('should handle the update of the workspace with multiple stacks gracefully', async ({
83133
page,
84134
context

packages/ui/src/lib/components/IntegrationSeriesRow.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import Checkbox from '$components/Checkbox.svelte';
2626
import Icon from '$components/Icon.svelte';
2727
import SeriesIcon from '$components/SeriesIcon.svelte';
28+
import { TestId } from '$lib/utils/testIds';
2829
const {
2930
testId,
3031
series,
@@ -37,13 +38,16 @@
3738
</script>
3839

3940
{#snippet stackBranch({ name, status }: Branch, isLast: boolean)}
40-
<div class="series-branch {status}">
41+
<div class="series-branch {status}" data-integration-row-branch-name={name}>
4142
<div class="structure-lines" class:last={isLast}></div>
4243
<div class="branch-info">
4344
<span class="text-12 text-semibold truncate">{name}</span>
4445

4546
{#if status}
46-
<span class="status-badge text-10 text-semibold">
47+
<span
48+
class="status-badge text-10 text-semibold"
49+
data-testid={TestId.IntegrateUpstreamSeriesRowStatusBadge}
50+
>
4751
{#if status === 'conflicted'}
4852
Conflicted
4953
{:else if status === 'integrated'}

packages/ui/src/lib/utils/testIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export enum TestId {
5353
IntegrateUpstreamCommitsButton = 'integrate-upstream-commits-button',
5454
IntegrateUpstreamCommitsModal = 'integrate-upstream-commits-modal',
5555
IntegrateUpstreamSeriesRow = 'integrate-upstream-series-row',
56+
IntegrateUpstreamSeriesRowStatusBadge = 'integrate-upstream-series-row-status-badge',
5657
IntegrateUpstreamActionButton = 'integrate-upstream-action-button',
5758
FileListModeOption = 'file-list-mode-option',
5859
FileListTreeFolder = 'file-list-tree-folder',

0 commit comments

Comments
 (0)