Skip to content

Add no verify for commit with documentation #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit testing for commit with option no-verify
Signed-off-by: Agora Security <github@agora-security.com>
  • Loading branch information
AgoraSecurity committed Feb 21, 2020
commit 00208525ee0d2a77d77f7e8a885af7e2d65334ad
31 changes: 31 additions & 0 deletions tests/units/test_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down