Skip to content

Commit 8477ca4

Browse files
committed
feat(tests): add reusable script to apply upstream branch
Add a new helper script (apply-upstream-branch.sh) used by Playwright e2e tests to apply a remote branch into a cloned test workspace. The script prints environment debug info, accepts branch and directory arguments, and runs the stack-branches command with -u for upstream applies. Introduce project-with-stacks.sh to create a remote git repo with multiple independent branches and clone it into local-clone. This replaces and consolidates previous test setup logic. Update tests (branches.spec.ts) to call the new apply-upstream-branch script with explicit branch and directory parameters instead of the removed project-with-remote-branches__apply-branch-1.sh script. Remove obsolete project-with-remote-branches__apply-branch-1.sh. The changes make branch application reusable and parameterized, improving test clarity and reducing duplication.
1 parent b68ddec commit 8477ca4

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 TO APPLY: $1"
7+
echo "DIRECTORY: $2"
8+
9+
# Apply remote branch to the workspace.
10+
pushd "$2"
11+
$BUT_TESTING -j stack-branches -u -b $1
12+
popd

e2e/playwright/scripts/project-with-remote-branches__apply-branch-1.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
7+
# Setup a remote project.
8+
# GitButler currently requires projects to have a remote
9+
mkdir remote-project
10+
pushd remote-project
11+
git init -b master --object-format=sha1
12+
echo "foo" >> a_file
13+
echo "bar" >> a_file
14+
echo "baz" >> a_file
15+
git add a_file
16+
git commit -am "Hey, look! A commit."
17+
18+
# Create branch 1
19+
git checkout -b branch1
20+
echo "branch1 commit 1" >> a_file
21+
git commit -am "branch1: first commit"
22+
echo "branch1 commit 2" >> a_file
23+
git commit -am "branch1: second commit"
24+
echo "branch1 commit 1" >> a_file
25+
git commit -am "branch1: third commit"
26+
echo "branch1 commit 2" >> a_file
27+
git commit -am "branch1: fourth commit"
28+
git checkout master
29+
30+
# Create branch 2
31+
# Branch 2 is independent
32+
git checkout -b branch2
33+
echo "branch2 commit 1" >> b_file
34+
git add b_file
35+
git commit -am "branch2: first commit"
36+
echo "branch2 commit 2" >> b_file
37+
git commit -am "branch2: second commit"
38+
git checkout master
39+
40+
# Create branch 3, also independent
41+
git checkout -b branch3
42+
echo "branch3 commit 1" >> c_file
43+
git add c_file
44+
git commit -am "branch3: first commit"
45+
echo "branch3 commit 2" >> c_file
46+
git commit -am "branch3: second commit"
47+
git checkout master
48+
popd
49+
50+
# Clone the remote into a folder and add the project to the application.
51+
git clone remote-project local-clone
52+
pushd local-clone
53+
git checkout master
54+
$BUT_TESTING add-project --switch-to-workspace "$(git rev-parse --symbolic-full-name @{u})"
55+
popd

e2e/playwright/tests/branches.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test('should be able to apply a remote branch and integrate the remote changes -
137137
const fileCPath = gitbutler.pathInWorkdir('local-clone/c_file');
138138

139139
await gitbutler.runScript('project-with-remote-branches.sh');
140-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
140+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
141141

142142
await page.goto('/');
143143

@@ -197,7 +197,7 @@ test('should be able to apply a remote branch and integrate the remote changes -
197197
const filePath = gitbutler.pathInWorkdir('local-clone/a_file');
198198

199199
await gitbutler.runScript('project-with-remote-branches.sh');
200-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
200+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
201201

202202
await page.goto('/');
203203

@@ -543,7 +543,7 @@ test('should handle gracefully applying two conflicting branches', async ({
543543
gitbutler = await startGitButler(workdir, configdir, context);
544544

545545
await gitbutler.runScript('project-with-remote-branches.sh');
546-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
546+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
547547

548548
await page.goto('/');
549549

0 commit comments

Comments
 (0)