From 39d77d5ffa1cfb16cd4a90d9127262257f993d0d Mon Sep 17 00:00:00 2001 From: Agora Security <github@agora-security.com> Date: Fri, 21 Feb 2020 13:10:18 -0500 Subject: [PATCH 1/4] Add yard doc for changes in #commit Signed-off-by: Agora Security <github@agora-security.com> --- lib/git/lib.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 8aa7d27d..b4d40191 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -550,6 +550,18 @@ def remove(path = '.', opts = {}) command('rm', arr_opts) end + # Takes the commit message with the options and executes the commit command + # + # accepts options: + # :amend + # :all + # :allow_empty + # :author + # :date + # :no_verify + # + # @param [String] message the commit message to be used + # @param [Array] opts the commit options to be used def commit(message, opts = {}) arr_opts = [] arr_opts << "--message=#{message}" if message From 00208525ee0d2a77d77f7e8a885af7e2d65334ad Mon Sep 17 00:00:00 2001 From: Agora Security <github@agora-security.com> Date: Fri, 21 Feb 2020 13:48:47 -0500 Subject: [PATCH 2/4] Add unit testing for commit with option no-verify Signed-off-by: Agora Security <github@agora-security.com> --- tests/units/test_lib.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index 8796dc88..c007d168 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -44,6 +44,37 @@ def test_commit_with_date assert_equal("Scott Chacon <schacon@gmail.com> #{author_date.strftime("%s %z")}", data['author']) end + def test_commit_with_no_verify + # Backup current pre-commit hook + pre_commit_path = "#{@wdir}/.git/hooks/pre-commit" + pre_commit_path_bak = "#{pre_commit_path}-bak" + move_file(pre_commit_path, pre_commit_path_bak) + + # Adds a pre-commit file that should throw an error + create_file(pre_commit_path, 'echo Pre-commit file. Shoud not execute; exit 1') # Error when executed + File.chmod(0111, pre_commit_path) + + create_file("#{@wdir}/test_file_2", 'content test_file_2') + @lib.add('test_file_2') + + # Error raised because of pre-commit hook and no use of no_verify option + assert_raise Git::GitExecuteError do + @lib.commit('commit without no verify and pre-commit file') + end + + # Error is not raised when no_verify is passed + assert_nothing_raised do + @lib.commit('commit with no verify and pre-commit file', no_verify: true ) + end + + # Restore pre-commit hook + move_file(pre_commit_path_bak, pre_commit_path) + + # Verify the commit was created + data = @lib.commit_data('HEAD') + assert_equal("commit with no verify and pre-commit file\n", data['message']) + end + def test_checkout assert(@lib.checkout('test_checkout_b',{:new_branch=>true})) assert(@lib.checkout('master')) From 9043daf6cf5ff81557e68f5ef4480fd903df3866 Mon Sep 17 00:00:00 2001 From: Agora Security <github@agora-security.com> Date: Fri, 21 Feb 2020 13:48:27 -0500 Subject: [PATCH 3/4] Add function to move files Signed-off-by: Agora Security <github@agora-security.com> --- tests/test_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_helper.rb b/tests/test_helper.rb index 3f5a4665..b0b3f80c 100644 --- a/tests/test_helper.rb +++ b/tests/test_helper.rb @@ -69,6 +69,10 @@ def update_file(path, content) def delete_file(path) File.delete(path) end + + def move_file(source_path, target_path) + File.rename source_path, target_path + end def new_file(name, contents) create_file(name,contents) From edd2c1f90bf13e2faee9abe8aa4e41592c028ec2 Mon Sep 17 00:00:00 2001 From: Agora Security <github@agora-security.com> Date: Thu, 7 Nov 2019 12:23:56 -0600 Subject: [PATCH 4/4] Add no verify for commit In git commit, add: -n, --no-verify This option bypasses the pre-commit and commit-msg hooks. See also githooks(5). Signed-off-by: Agora@Ubuntu-dev <filter@agora-security.com> Signed-off-by: Agora Security <github@agora-security.com> --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index b4d40191..3045262d 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -570,6 +570,7 @@ def commit(message, opts = {}) arr_opts << '--allow-empty' if opts[:allow_empty] arr_opts << "--author=#{opts[:author]}" if opts[:author] arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String + arr_opts << '--no-verify' if opts[:no_verify] command('commit', arr_opts) end