From 0261621287a78ba4e40e82765a01842e81ebfab0 Mon Sep 17 00:00:00 2001 From: Shivam Mukhade Date: Fri, 10 Dec 2021 14:30:05 +0530 Subject: [PATCH] Returns branch name as `main` if ref as `refs-heads-main` (#392) --- pkg/formatting/vcs.go | 3 ++ pkg/formatting/vcs_test.go | 5 +++ .../survey/v2/terminal/LICENSE.txt | 44 +++++++++---------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/pkg/formatting/vcs.go b/pkg/formatting/vcs.go index cebecbf8a..f8381f4f1 100644 --- a/pkg/formatting/vcs.go +++ b/pkg/formatting/vcs.go @@ -12,6 +12,9 @@ func SanitizeBranch(s string) string { if strings.HasPrefix(s, "refs/heads/") { return strings.TrimPrefix(s, "refs/heads/") } + if strings.HasPrefix(s, "refs-heads-") { + return strings.TrimPrefix(s, "refs-heads-") + } return s } diff --git a/pkg/formatting/vcs_test.go b/pkg/formatting/vcs_test.go index e7dbc99bb..fad6ba149 100644 --- a/pkg/formatting/vcs_test.go +++ b/pkg/formatting/vcs_test.go @@ -97,6 +97,11 @@ func TestSanitizeBranch(t *testing.T) { args: args{s: "refs/tags/1.0"}, want: "refs/tags/1.0", }, + { + name: "sanitize main ref", + args: args{s: "refs-heads-main"}, + want: "main", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt b/vendor/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt index 82e7ce0d4..ade5fef6d 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt @@ -1,22 +1,22 @@ -Copyright (c) 2014 Takashi Kokubun - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Copyright (c) 2014 Takashi Kokubun + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.