From bacad965238158b9ae6ff438ba923725ec128020 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 16 Feb 2020 00:03:13 +0000 Subject: github #48/0001: vcs_info git: avoid warnings in bare repositories Git 2.25 introduced a change to how git rev-parse --show-toplevel behaves. Traditionally, it succeeded with no output if the user was in a bare repository. Now it dies, printing an error to standard error. Consequently, when the user is in a bare repository with a newer Git, vcs_info prints noisily to standard error. While this is functionally harmless, it is annoying for the shell to print messages from Git every time the prompt is printed, so let's silence the error message. --- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Functions/VCS_Info/Backends/VCS_INFO_get_data_git') diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index ceb4f978a..0128c0981 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -138,7 +138,7 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} -gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel ) +gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) rrn=${gitbase:t} if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD) -- cgit 1.4.1 From 51260963703bbc91944434648ae71a05addbcb05 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 16 Feb 2020 20:54:12 +0000 Subject: github #48/0002: vcs_info git: properly detect bare repositories We currently detect Git repositories by finding the top level of the working tree, and if we fail to detect it, assume that we're not in a repository. However, there's a case we don't consider: a bare repository. Let's detect if the user is in a bare repository by checking if gitdir is set, and if so, using that if there is no working tree. We now detect bare Git repositories with vcs_info, as expected. --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'Functions/VCS_Info/Backends/VCS_INFO_get_data_git') diff --git a/ChangeLog b/ChangeLog index 75751a547..290f1c6af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-02-17 brian m. carlson + * github #48/0002: + Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: + properly detect bare repositories + * github #48/0001: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: avoid warnings in bare repositories diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 0128c0981..5ddce72a6 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -139,6 +139,10 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) +if [[ -z ${gitbase} ]]; then + # Bare repository + gitbase=${gitdir:P} +fi rrn=${gitbase:t} if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD) -- cgit 1.4.1