git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] t9903: add upstream indicator tests

From
KGKiril Ivanov via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 15, 2025, 18:54 UTC
Message-ID
<af5861933fe4f2f4aa4c81e080a035ce5cd45c34.1763232863.git.gitgitgadget@gmail.com>
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
Previous: Kiril Ivanov via GitGitGadgetNext: Kiril Ivanov via GitGitGadget
Message 3 of 10 in “git-prompt: add quiet upstream indicator option”
  1. 0/3 git-prompt: add quiet upstream indicator optionKiril Ivanov via GitGitGadget, Nov 15, 2025
  2. 1/3 t9903: shorten setup using test_commitKiril Ivanov via GitGitGadget, Nov 15, 2025
  3. 2/3 t9903: add upstream indicator testsKiril Ivanov via GitGitGadget, Nov 15, 2025
  4. 3/3 git-prompt: add quiet upstream indicator optionKiril Ivanov via GitGitGadget, Nov 15, 2025
  5. D. Ben KnobleNov 20, 2025
  6. Eric SunshineNov 20, 2025
  7. D. Ben KnobleNov 20, 2025
  8. Junio C HamanoNov 15, 2025
  9. Kiril IvanovNov 16, 2025
  10. Junio C HamanoNov 16, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.