From d1e4c63c52180495049c8d9eb2f92de4d0cc3337 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Mon, 11 Mar 2024 14:13:26 +0000 Subject: [PATCH] Fix early wrapping of the command line when using git-prompt.sh When running git-prompt in Bash, the lack of \001 and \002 causes the command line to wrap early. The issue is the current \001 and \002 were not themselves escaped and so resulted in binary 0b1 and 0b10 being present, rather than the strings "\001" and "\002". --- contrib/completion/git-prompt.sh | 8 ++++---- t/t9903-bash-prompt.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 71f179cba3fbda..6585164efe67b9 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -259,10 +259,10 @@ __git_ps1_colorize_gitstring () else # Using \001 and \002 around colors is necessary to prevent # issues with command line editing/browsing/completion! - local c_red=$'\001\e[31m\002' - local c_green=$'\001\e[32m\002' - local c_lblue=$'\001\e[1;34m\002' - local c_clear=$'\001\e[0m\002' + local c_red=$'\\001\e[31m\\002' + local c_green=$'\\001\e[32m\\002' + local c_lblue=$'\\001\e[1;34m\\002' + local c_clear=$'\\001\e[0m\\002' fi local bad_color=$c_red local ok_color=$c_green diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index d667dda654e2de..fc6fdd36c69de2 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -13,10 +13,10 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" actual="$TRASH_DIRECTORY/actual" -c_red='\001\e[31m\002' -c_green='\001\e[32m\002' -c_lblue='\001\e[1;34m\002' -c_clear='\001\e[0m\002' +c_red='\\001\e[31m\\002' +c_green='\\001\e[32m\\002' +c_lblue='\\001\e[1;34m\\002' +c_clear='\\001\e[0m\\002' test_expect_success 'setup for prompt tests' ' git init otherrepo &&