From: "Kiril Ivanov via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: Kiril Ivanov <ivanovkirilg@gmail•com>,
Kiril Ivanov <ivanovkirilg@gmail•com>
Subject: [PATCH 2/3] t9903: add upstream indicator tests
Date: Sat, 15 Nov 2025 18:54:22 +0000 [thread overview]
Message-ID: <af5861933fe4f2f4aa4c81e080a035ce5cd45c34.1763232863.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2101.git.git.1763232863.gitgitgadget@gmail.com>
From: Kiril Ivanov <ivanovkirilg@gmail•com>
The upstream indicator currently has no test coverage.
Since GIT_PS1_SHOWUPSTREAM supports various options, make these tests
parameterized with a matrix for expected results (ahead/behind/etc).
Signed-off-by: Kiril Ivanov <ivanovkirilg@gmail•com>
---
t/t9903-bash-prompt.sh | 59 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 7628bc10fe..3997012d1c 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -25,6 +25,8 @@ c_clear='\001\e[0m\002'
# (b2)
test_expect_success 'setup for prompt tests' '
git init otherrepo &&
+ git init --bare origin.git &&
+ git remote add origin origin.git &&
test_commit --annotate initial file contents1 t1 &&
git checkout -b b1 &&
test_commit --no-tag second-b1 file &&
@@ -35,6 +37,7 @@ test_expect_success 'setup for prompt tests' '
test_commit --no-tag yet-another-b2 file &&
mkdir ignored_dir &&
echo "ignored_dir/" >>.gitignore &&
+ git push --set-upstream origin main b1 b2 &&
git checkout main
'
@@ -515,6 +518,62 @@ test_expect_success 'prompt - untracked files status indicator - not shown insid
test_cmp expected "$actual"
'
+################################################################
+# Show Upstream
+options=( short verbose 'verbose name' )
+expected_equal=( ' =' '|u=' '|u= origin/main' )
+expected_ahead=( ' >' '|u+1' '|u+1 origin/main')
+expected_behind=( ' <' '|u-1' '|u-1 origin/b1' )
+expected_diverged=(' <>' '|u+1-1' '|u+1-1 origin/b1')
+
+for i in ${!options[@]}
+do
+ option=${options[$i]}
+
+ test_expect_success "prompt - upstream status indicator - $option - equal" '
+ printf " (main${expected_equal[$i]})" >expected &&
+ GIT_PS1_SHOWUPSTREAM=$option &&
+ test_when_finished "sane_unset GIT_PS1_SHOWUPSTREAM" &&
+ __git_ps1 >"$actual" &&
+ test_cmp expected "$actual"
+ '
+
+ test_expect_success "prompt - upstream status indicator - $option - ahead" '
+ printf " (main${expected_ahead[$i]})" >expected &&
+ GIT_PS1_SHOWUPSTREAM=$option &&
+ test_when_finished "sane_unset GIT_PS1_SHOWUPSTREAM" &&
+ test_commit --no-tag ahead &&
+ test_when_finished "git reset HEAD^" &&
+ __git_ps1 >"$actual" &&
+ test_cmp expected "$actual"
+ '
+
+ test_expect_success "prompt - upstream status indicator - $option - behind" '
+ printf " (b1${expected_behind[$i]})" >expected &&
+ GIT_PS1_SHOWUPSTREAM=$option &&
+ test_when_finished "sane_unset GIT_PS1_SHOWUPSTREAM" &&
+ git checkout b1 &&
+ test_when_finished "git checkout main" &&
+ git reset HEAD^ &&
+ test_when_finished "git reset @{u}" &&
+ __git_ps1 >"$actual" &&
+ test_cmp expected "$actual"
+ '
+
+ test_expect_success "prompt - upstream status indicator - $option - diverged" '
+ printf " (b1${expected_diverged[$i]})" >expected &&
+ GIT_PS1_SHOWUPSTREAM=$option &&
+ test_when_finished "sane_unset GIT_PS1_SHOWUPSTREAM" &&
+ git checkout b1 &&
+ test_when_finished "git checkout main" &&
+ git reset HEAD^ &&
+ test_when_finished "git reset @{u}" &&
+ test_commit --no-tag ahead &&
+ __git_ps1 >"$actual" &&
+ test_cmp expected "$actual"
+ '
+done
+
test_expect_success 'prompt - format string starting with dash' '
printf -- "-main" >expected &&
__git_ps1 "-%s" >"$actual" &&
--
gitgitgadget
next prev parent reply other threads:[~2025-11-15 18:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-15 18:54 [PATCH 0/3] git-prompt: add quiet upstream indicator option Kiril Ivanov via GitGitGadget
2025-11-15 18:54 ` [PATCH 1/3] t9903: shorten setup using test_commit Kiril Ivanov via GitGitGadget
2025-11-15 18:54 ` Kiril Ivanov via GitGitGadget [this message]
2025-11-15 18:54 ` [PATCH 3/3] git-prompt: add quiet upstream indicator option Kiril Ivanov via GitGitGadget
2025-11-20 16:01 ` D. Ben Knoble
2025-11-20 18:05 ` Eric Sunshine
2025-11-20 18:18 ` D. Ben Knoble
2025-11-15 20:07 ` [PATCH 0/3] " Junio C Hamano
2025-11-16 12:05 ` Kiril Ivanov
2025-11-16 16:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af5861933fe4f2f4aa4c81e080a035ce5cd45c34.1763232863.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=ivanovkirilg@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox