From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jess Austin Subject: [PATCH] git-prompt.sh: Omit prompt for ignored directories Date: Wed, 8 Oct 2014 14:04:00 -0500 Message-ID: <1412795040-19267-1-git-send-email-jess.austin@gmail.com> Cc: Jess Austin , szeder@ira.uka.de, rhansen@bbn.com To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Wed Oct 08 21:04:40 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XbwXP-0007zL-6S for gcvg-git-2@plane.gmane.org; Wed, 08 Oct 2014 21:04:39 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753868AbaJHTEc (ORCPT ); Wed, 8 Oct 2014 15:04:32 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:64592 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753273AbaJHTEb (ORCPT ); Wed, 8 Oct 2014 15:04:31 -0400 Received: by mail-ig0-f169.google.com with SMTP id uq10so10494411igb.0 for ; Wed, 08 Oct 2014 12:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=n7TCPLrVqnfTf6n6LeSidnNta3otcV3eEpJU0UcCB5Q=; b=iKJTxxISV7w2M7EHBIbEjdCbAwzeg+wMyZTE4HTdVV43+WceyBdIEhGvH2rX5lSZws rYhJ+Wnn9IiNwbvjqTa18kBgoigM+1FUZS5B3tigLsvGYm6JbG/ytyzQkVPwlfIrNSNk dkLndG0tl4EKxsp5DgKDyHfpB9Rz84vGnx+H0S69bQRf4cMEk4I9SMEdzM31qX9sMo8a 5kBzNLX8gbUS6pKmiE3GjPvCmM8Ftj8lQbora07vGyqi60a8jlwlKECRkq34nWTdhnyn 5O0A0YLlcW9/sZT9cC14qTM6jGKlermOIqfpA1xIVnphjXJ4/KVJiqLHZyFgyWlvxc7j 8ayA== X-Received: by 10.50.67.109 with SMTP id m13mr19574310igt.39.1412795070554; Wed, 08 Oct 2014 12:04:30 -0700 (PDT) Received: from localhost.localdomain (66-128-122-45.static.stls.mo.charter.com. [66.128.122.45]) by mx.google.com with ESMTPSA id p10sm1955271igx.2.2014.10.08.12.04.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Oct 2014 12:04:29 -0700 (PDT) X-Mailer: git-send-email 1.9.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which tells __git_ps1 to display nothing when the current directory is set (e.g. via .gitignore) to be ignored by git. In the absence of GIT_PS1_OMITIGNORED this change has no effect. Many people manage e.g. dotfiles in their home directory with git. This causes the prompt generated by __git_ps1 to refer to that "top level" repo while working in any descendant directory. That can be distracting, so this patch helps one shut off that noise. Signed-off-by: Jess Austin --- contrib/completion/git-prompt.sh | 9 +++++++++ t/t9903-bash-prompt.sh | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index c5473dc..6a26cb4 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -84,6 +84,10 @@ # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on # the colored output of "git status -sb" and are available only when # using __git_ps1 for PROMPT_COMMAND or precmd. +# +# If you would like __git_ps1 to do nothing in the case when the current +# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED +# to a nonempty value. # check whether printf supports -v __git_printf_supports_v= @@ -501,6 +505,11 @@ __git_ps1 () local f="$w$i$s$u" local gitstring="$c$b${f:+$z$f}$r$p" + if [ -n "$(git check-ignore .)" ] && [ -n "${GIT_PS1_OMITIGNORED}" ] + then + printf_format="" + fi + if [ $pcmode = yes ]; then if [ "${__git_printf_supports_v-}" != yes ]; then gitstring=$(printf -- "$printf_format" "$gitstring") diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 9150984..55bcb6b 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' ' git commit -m "another b2" file && echo 000 >file && git commit -m "yet another b2" file && + mkdir ignored_dir && + echo "ignored_dir/" >> .gitignore && git checkout master ' @@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' ' test_cmp expected "$actual" ' +test_expect_success 'prompt - prompt omitted in ignored directory' ' + printf "" >expected && + ( + cd ignored_dir && + GIT_PS1_OMITIGNORED=y && + __git_ps1 >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' ' + printf " (master)" >expected && + ( + cd ignored_dir && + __git_ps1 >"$actual" + ) && + test_cmp expected "$actual" +' + test_done -- 1.9.1