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

Michał Górny <[email protected]> Wed, 05 Aug 2026 11:34:23 +0000 (UTC)
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1785929653.f05e34cb5cf47baad0796545e30247a6ec23f9d6.mgorny@gentoo>
commit:     f05e34cb5cf47baad0796545e30247a6ec23f9d6
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  5 11:34:13 2026 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Aug  5 11:34:13 2026 +0000
URL:        https://gitweb.gentoo.org/proj/gagit.git/commit/?id=f05e34cb

Add a bunch of tests for error scenarios

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

 meson.build                      |  7 +++++++
 test/00no-repository.sh          |  8 ++------
 test/01no-codeberg-remote.sh     | 13 +++++++++++++
 test/01no-remote.sh              | 11 +++++++++++
 test/01no-ssh-codeberg-remote.sh | 13 +++++++++++++
 test/02no-branch.sh              | 12 ++++++++++++
 test/02wrong-branch.sh           | 17 +++++++++++++++++
 test/03no-target-branch.sh       | 15 +++++++++++++++
 test/04no-commits.sh             | 11 +++++++++++
 test/common-setup.sh             | 30 ++++++++++++++++++++++++++++++
 10 files changed, 131 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index b168d63..5cb9278 100644
--- a/meson.build
+++ b/meson.build
@@ -12,6 +12,13 @@ install_data('gagit',
 bash = find_program('bash')
 tests = [
   '00no-repository',
+  '01no-remote',
+  '01no-codeberg-remote',
+  '01no-ssh-codeberg-remote',
+  '02no-branch',
+  '02wrong-branch',
+  '03no-target-branch',
+  '04no-commits',
 ]
 
 foreach t : tests

diff --git a/test/00no-repository.sh b/test/00no-repository.sh
index 8ceaf46..32120cd 100755
--- a/test/00no-repository.sh
+++ b/test/00no-repository.sh
@@ -1,13 +1,9 @@
-#!/bin/sh
+#!/usr/bin/env bash
 # Test whether a clear error is given when not in a repository.
 
 set -e -x
 
-INITDIR=${PWD}
-TEMPDIR=$(mktemp -d)
-trap 'rm -rf "${TEMPDIR}"' EXIT
-
-cd "${TEMPDIR}"
+. common-setup.sh
 
 STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
 [[ ${STDERR} == *'needs to be run inside a git checkout'* ]]

diff --git a/test/01no-codeberg-remote.sh b/test/01no-codeberg-remote.sh
new file mode 100644
index 0000000..cbedc94
--- /dev/null
+++ b/test/01no-codeberg-remote.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there is no remote that looks
+# like Codeberg.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+git remote add codeberg "https://example.com/example.git"
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote not found'* ]]
+[[ ${STDERR} != *'error: No such remote'* ]]

diff --git a/test/01no-remote.sh b/test/01no-remote.sh
new file mode 100644
index 0000000..c8ddf4e
--- /dev/null
+++ b/test/01no-remote.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there is no remote.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote not found'* ]]
+[[ ${STDERR} != *'error: No such remote'* ]]

diff --git a/test/01no-ssh-codeberg-remote.sh b/test/01no-ssh-codeberg-remote.sh
new file mode 100644
index 0000000..1bd482b
--- /dev/null
+++ b/test/01no-ssh-codeberg-remote.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there is no SSH-based
+# Codeberg remote.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+git remote add codeberg "https://codeberg.org/gentoo/example"
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Codeberg remote not found'* ]]
+[[ ${STDERR} != *'error: No such remote'* ]]

diff --git a/test/02no-branch.sh b/test/02no-branch.sh
new file mode 100644
index 0000000..ff0febe
--- /dev/null
+++ b/test/02no-branch.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there is no branch.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+git remote add codeberg "ssh://[email protected]/gentoo/example"
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Please run gagit on a new feature branch'* ]]
+[[ ${STDERR} != *'unknown revision'* ]]

diff --git a/test/02wrong-branch.sh b/test/02wrong-branch.sh
new file mode 100644
index 0000000..0a0475b
--- /dev/null
+++ b/test/02wrong-branch.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when we are on incorrect branch.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+git remote add codeberg "ssh://[email protected]/gentoo/example"
+
+for branch in dev main master; do
+	git checkout -b "${branch}"
+	git commit --allow-empty -m init
+
+	STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+	[[ ${STDERR} == *'Please run gagit on a new feature branch'* ]]
+	[[ ${STDERR} != *'unknown revision'* ]]
+done

diff --git a/test/03no-target-branch.sh b/test/03no-target-branch.sh
new file mode 100644
index 0000000..156300d
--- /dev/null
+++ b/test/03no-target-branch.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there is no target branch.
+
+set -e -x
+
+. common-setup.sh
+make_repository
+git remote add codeberg "ssh://[email protected]/gentoo/example"
+
+git checkout -b foo
+git commit --allow-empty -m init
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'Unable to find a target branch'* ]]
+[[ ${STDERR} != *'unknown revision'* ]]

diff --git a/test/04no-commits.sh b/test/04no-commits.sh
new file mode 100644
index 0000000..b8221c4
--- /dev/null
+++ b/test/04no-commits.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# Test whether a clear error is given when there are no commits
+# on the target branch.
+
+set -e -x
+
+. common-setup.sh
+repository_setup
+
+STDERR=$(! bash "${INITDIR}"/../gagit -e false -n 2>&1 >/dev/null)
+[[ ${STDERR} == *'No changes found'* ]]

diff --git a/test/common-setup.sh b/test/common-setup.sh
new file mode 100644
index 0000000..ad6ffe5
--- /dev/null
+++ b/test/common-setup.sh
@@ -0,0 +1,30 @@
+INITDIR=${PWD}
+TEMPDIR=$(mktemp -d)
+trap 'rm -rf "${TEMPDIR}"' EXIT
+
+# Use predefined timestamp to get reproducible repo.
+export GIT_AUTHOR_DATE='2000-01-01 00:00:00Z'
+export GIT_COMMITTER_DATE='2000-01-01 00:00:00Z'
+
+export EDITOR=:
+
+cd "${TEMPDIR}"
+
+make_repository() {
+	git init
+	git config --local user.name 'gagit test'
+	git config --local user.email '[email protected]'
+}
+
+repository_setup() {
+	local remote_name=${1:-codeberg}
+	local feature_branch=${2:-foo}
+	local target_branch=${3:-dev}
+
+	make_repository
+	git remote add "${remote_name}" "ssh://[email protected]/gentoo/example"
+	git checkout -b "${target_branch}"
+	git commit --allow-empty -m init
+	git update-ref "refs/remotes/${remote_name}/${target_branch}" HEAD
+	git checkout -b "${feature_branch}"
+}