From b327a93e5fd026e2faedda200d1709e70f76b8d7 Mon Sep 17 00:00:00 2001
From: Daniel Paul Searles <dsearles@gitlab.com>
Date: Mon, 1 Jun 2020 15:32:12 -0700
Subject: [PATCH] Fix the default sha for bin/secpick

Why:

* The shell command to read the current sha has an ending newline that
  should be stripped.

This change addresses the need by:

* strip whitespace from sha when reading the current sha
* refactor original_branch to strip whitespace at the point it could be
  introduced
---
 bin/secpick | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/bin/secpick b/bin/secpick
index 4d056ceecaf02..517465d3f5d1b 100755
--- a/bin/secpick
+++ b/bin/secpick
@@ -25,12 +25,8 @@ module Secpick
       @options[:try] == true
     end
 
-    def original_branch
-      @options[:branch].strip
-    end
-
     def source_branch
-      branch = "#{original_branch}-#{@options[:version]}"
+      branch = "#{@options[:branch]}-#{@options[:version]}"
       branch.prepend("#{BRANCH_PREFIX}-") unless branch.start_with?("#{BRANCH_PREFIX}-")
       branch.freeze
     end
@@ -44,7 +40,7 @@ module Secpick
        "git checkout -B #{source_branch} #{@options[:remote]}/#{stable_branch} --no-track",
        "git cherry-pick #{@options[:sha]}",
        "git push #{@options[:remote]} #{source_branch}",
-       "git checkout #{original_branch}"]
+       "git checkout #{@options[:branch]}"]
     end
 
     def gitlab_params
@@ -121,8 +117,8 @@ module Secpick
 
         parser.parse!
 
-        options[:sha] ||= `git rev-parse HEAD`
-        options[:branch] ||= `git rev-parse --abbrev-ref HEAD`
+        options[:sha] ||= `git rev-parse HEAD`.strip
+        options[:branch] ||= `git rev-parse --abbrev-ref HEAD`.strip
         options[:remote] ||= DEFAULT_REMOTE
 
         nil_options = options.select {|_, v| v.nil? }
-- 
GitLab