proj/gagit:main commit in: test/, /

Michał Górny <[email protected]> Wed, 05 Aug 2026 14:30:50 +0000 (UTC)
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1785940236.a6809dd55f99d45ff962e6d0063167404cc13c01.mgorny@gentoo>
commit:     a6809dd55f99d45ff962e6d0063167404cc13c01
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  5 14:30:36 2026 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Aug  5 14:30:36 2026 +0000
URL:        https://gitweb.gentoo.org/proj/gagit.git/commit/?id=a6809dd5

Add another batch of functionality tests

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 meson.build                              |  6 ++++++
 test/{02no-branch.sh => 02empty-repo.sh} |  2 +-
 test/02no-branch.sh                      | 12 ++++++++++-
 test/05editor-failed.sh                  | 11 ++++++++++
 test/20baseline.sh                       | 36 ++++++++++++++++++++++++++++++++
 test/21remotes.sh                        | 28 +++++++++++++++++++++++++
 test/22target-branches.sh                | 26 +++++++++++++++++++++++
 test/23topic.sh                          | 14 +++++++++++++
 8 files changed, 133 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index 5cb9278..7b4474f 100644
--- a/meson.build
+++ b/meson.build
@@ -16,9 +16,15 @@ tests = [
   '01no-codeberg-remote',
   '01no-ssh-codeberg-remote',
   '02no-branch',
+  '02empty-repo',
   '02wrong-branch',
   '03no-target-branch',
   '04no-commits',
+  '05editor-failed',
+  '20baseline',
+  '21remotes',
+  '22target-branches',
+  '23topic',
 ]
 
 foreach t : tests

diff --git a/test/02no-branch.sh b/test/02empty-repo.sh
similarity index 81%
copy from test/02no-branch.sh
copy to test/02empty-repo.sh
index ff0febe..db68a06 100644
--- a/test/02no-branch.sh
+++ b/test/02empty-repo.sh
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-# Test whether a clear error is given when there is no branch.
+# Test whether a clear error is given when the repository is empty.
 
 set -e -x
 

diff --git a/test/02no-branch.sh b/test/02no-branch.sh
index ff0febe..89d0e8d 100644
--- a/test/02no-branch.sh
+++ b/test/02no-branch.sh
@@ -1,11 +1,21 @@
 #!/usr/bin/env bash
-# Test whether a clear error is given when there is no branch.
+# Test whether a clear error is given when the repository is not checked
+# out on a branch.
 
 set -e -x
 
 . common-setup.sh
 make_repository
 git remote add codeberg "ssh://[email protected]/gentoo/example"
+git checkout -b dev
+git commit --allow-empty -m init
+git checkout --detach
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Please run gagit on a new feature branch'* ]]
+[[ ${STDERR} != *'unknown revision'* ]]
+
+git tag foo
 
 STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
 [[ ${STDERR} == *'Please run gagit on a new feature branch'* ]]

diff --git a/test/05editor-failed.sh b/test/05editor-failed.sh
new file mode 100644
index 0000000..044e592
--- /dev/null
+++ b/test/05editor-failed.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when the editor fails.
+
+set -e -x
+
+. common-setup.sh
+repository_setup
+git commit --allow-empty -m "test commit"
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Editor failed'* ]]

diff --git a/test/20baseline.sh b/test/20baseline.sh
new file mode 100644
index 0000000..9a35314
--- /dev/null
+++ b/test/20baseline.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# Baseline test (PR title/desc from commits).
+
+set -e -x
+
+. common-setup.sh
+repository_setup codeberg foo dev
+git commit --allow-empty -m "test commit
+
+test body"
+
+# one commit should yield:
+# T: WIP: test commit
+# D: test body
+STDERR=$(bash "${INITDIR}"/../gagit -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote: codeberg'* ]]
+[[ ${STDERR} == *'Current branch: foo'* ]]
+[[ ${STDERR} == *'Target branch: dev'* ]]
+[[ ${STDERR} == *"+ 'git' 'fetch' 'codeberg'
++ 'git' 'config' 'branch.foo.remote' 'codeberg'
++ 'git' 'config' 'branch.foo.merge' 'refs/for/dev/foo'
++ 'git' 'push' '-o' 'title={base64}V0lQOiB0ZXN0IGNvbW1pdAo=' '-o' 'description={base64}dGVzdCBib2R5CgoKCgo="* ]]
+
+
+# two commits should yield:
+# T: WIP: second commit (and more)
+# B: empty (\n)
+git commit --allow-empty -m "second commit"
+STDERR=$(bash "${INITDIR}"/../gagit -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote: codeberg'* ]]
+[[ ${STDERR} == *'Current branch: foo'* ]]
+[[ ${STDERR} == *'Target branch: dev'* ]]
+[[ ${STDERR} == *"+ 'git' 'fetch' 'codeberg'
++ 'git' 'config' 'branch.foo.remote' 'codeberg'
++ 'git' 'config' 'branch.foo.merge' 'refs/for/dev/foo'
++ 'git' 'push' '-o' 'title={base64}V0lQOiBzZWNvbmQgY29tbWl0IChhbmQgbW9yZSkK' '-o' 'description={base64}Cg=="* ]]

diff --git a/test/21remotes.sh b/test/21remotes.sh
new file mode 100644
index 0000000..8c9ea2a
--- /dev/null
+++ b/test/21remotes.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# Test correct ordering of remotes.
+
+set -e -x
+
+. common-setup.sh
+repository_setup nonstandard-name foo dev
+git commit --allow-empty -m "test commit"
+
+for remote_name in nonstandard-name origin upstream codeberg; do
+	if [[ ${remote_name} != nonstandard-name ]]; then
+		git remote add "${remote_name}" "ssh://[email protected]/gentoo/example"
+		git update-ref "refs/remotes/${remote_name}/dev" dev
+	fi
+
+	STDERR=$(bash "${INITDIR}"/../gagit -n 2>&1 >/dev/null)
+	[[ ${STDERR} == *"Codeberg remote: ${remote_name}"* ]]
+	[[ ${STDERR} == *"+ 'git' 'fetch' '${remote_name}'"* ]]
+	[[ ${STDERR} == *"+ 'git' 'config' 'branch.foo.remote' '${remote_name}'"* ]]
+done
+
+# test explicit override
+for remote_name in nonstandard-name origin upstream codeberg; do
+	STDERR=$(bash "${INITDIR}"/../gagit -n -r "${remote_name}" 2>&1 >/dev/null)
+	[[ ${STDERR} == *"Codeberg remote: ${remote_name}"* ]]
+	[[ ${STDERR} == *"+ 'git' 'fetch' '${remote_name}'"* ]]
+	[[ ${STDERR} == *"+ 'git' 'config' 'branch.foo.remote' '${remote_name}'"* ]]
+done

diff --git a/test/22target-branches.sh b/test/22target-branches.sh
new file mode 100644
index 0000000..adeaee4
--- /dev/null
+++ b/test/22target-branches.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# Test correct ordering of target branches.
+
+set -e -x
+
+. common-setup.sh
+repository_setup codeberg foo master
+git commit --allow-empty -m "test commit"
+
+for target_branch in master main dev; do
+	if [[ ${target_branch} != master ]]; then
+		git branch "${target_branch}" master
+		git update-ref "refs/remotes/codeberg/${target_branch}" master
+	fi
+
+	STDERR=$(bash "${INITDIR}"/../gagit -n 2>&1 >/dev/null)
+	[[ ${STDERR} == *"Target branch: ${target_branch}"* ]]
+	[[ ${STDERR} == *"+ 'git' 'config' 'branch.foo.merge' 'refs/for/${target_branch}/foo'"* ]]
+done
+
+# test explicit override
+for target_branch in master main dev; do
+	STDERR=$(bash "${INITDIR}"/../gagit -n -T "${target_branch}" 2>&1 >/dev/null)
+	[[ ${STDERR} == *"Target branch: ${target_branch}"* ]]
+	[[ ${STDERR} == *"+ 'git' 'config' 'branch.foo.merge' 'refs/for/${target_branch}/foo'"* ]]
+done

diff --git a/test/23topic.sh b/test/23topic.sh
new file mode 100644
index 0000000..986736f
--- /dev/null
+++ b/test/23topic.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+# Test that --topic override is respected.
+
+set -e -x
+
+. common-setup.sh
+repository_setup codeberg foo dev
+git commit --allow-empty -m "test commit"
+
+STDERR=$(bash "${INITDIR}"/../gagit -n -o bar 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote: codeberg'* ]]
+[[ ${STDERR} == *'Current branch: foo'* ]]
+[[ ${STDERR} == *'Target branch: dev'* ]]
+[[ ${STDERR} == *"+ 'git' 'config' 'branch.foo.merge' 'refs/for/dev/bar'"* ]]