summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram <perl-rt@wizbit.be>2022-09-17 20:55:17 +0200
committerTony Cook <tony@develop-help.com>2022-09-19 15:03:34 +1000
commit95aca9b049c0a768ab80bef52b8162b498735588 (patch)
tree4bc08950c9c6c3b9ad9ce92f4596b3b37bbc58be
parent94e822ee24ba222efc1979d79e64ca7b2c0942cb (diff)
downloadperl-95aca9b049c0a768ab80bef52b8162b498735588.tar.gz
Use `git symbolic-ref` instead of `git branch`
`git branch` is a porcelain command and should not be used in scripts.[^1] It can also cause failures when: - color.ui in git config is set to 'always' - HEAD is detached (i.e. `git checkout blead^0`) In that case the current branch is colored and (partially) ends up in the `$branch` var. (The code did check that the branch name didn't start with `(` but that check doesn't really work when it's colored. In that case the 'branch name' starts with an escape sequence for the color) Example (without the patch): $ git config color.ui always $ git checkout blead^0 $ ./miniperl -Ilib make_patchnum.pl sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `git config branch.(detached.merge' sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `git config branch.(detached.remote' $ grep git_branch lib/Config_git.pl git_branch='(detached' $ grep git_branch lib/Config_git.pl | cat -A git_branch='^[[32m(detached'$ With the patch applied: $ ./miniperl -Ilib make_patchnum.pl Updating 'git_version.h' and 'lib/Config_git.pl' $ grep git_branch lib/Config_git.pl git_branch='' $ grep git_branch lib/Config_git.pl | cat -A git_branch=''$ [^1]: See https://git-blame.blogspot.com/2013/06/checking-current-branch-programatically.html which is a blog post from the git maintainer.
-rw-r--r--make_patchnum.pl3
1 files changed, 1 insertions, 2 deletions
diff --git a/make_patchnum.pl b/make_patchnum.pl
index 712eff2b9c..eceb45468c 100644
--- a/make_patchnum.pl
+++ b/make_patchnum.pl
@@ -162,8 +162,7 @@ elsif ($git_patch_file = read_file(".git_patch") and $git_patch_file !~ /\A\$For
$commit_title = "Snapshot of:";
}
elsif (-d "$srcdir/.git") {
- # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
- ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick("git branch");
+ ($branch) = backtick("git symbolic-ref -q HEAD") =~ m#^refs/heads/(.+)$#;
$branch //= "";
my ($remote,$merge);
if (length $branch) {