@@ -44,6 +44,37 @@ def test_commit_with_date
44
44
assert_equal ( "Scott Chacon <schacon@gmail.com> #{ author_date . strftime ( "%s %z" ) } " , data [ 'author' ] )
45
45
end
46
46
47
+ def test_commit_with_no_verify
48
+ # Backup current pre-commit hook
49
+ pre_commit_path = "#{ @wdir } /.git/hooks/pre-commit"
50
+ pre_commit_path_bak = "#{ pre_commit_path } -bak"
51
+ move_file ( pre_commit_path , pre_commit_path_bak )
52
+
53
+ # Adds a pre-commit file that should throw an error
54
+ create_file ( pre_commit_path , 'echo Pre-commit file. Shoud not execute; exit 1' ) # Error when executed
55
+ File . chmod ( 0111 , pre_commit_path )
56
+
57
+ create_file ( "#{ @wdir } /test_file_2" , 'content test_file_2' )
58
+ @lib . add ( 'test_file_2' )
59
+
60
+ # Error raised because of pre-commit hook and no use of no_verify option
61
+ assert_raise Git ::GitExecuteError do
62
+ @lib . commit ( 'commit without no verify and pre-commit file' )
63
+ end
64
+
65
+ # Error is not raised when no_verify is passed
66
+ assert_nothing_raised do
67
+ @lib . commit ( 'commit with no verify and pre-commit file' , no_verify : true )
68
+ end
69
+
70
+ # Restore pre-commit hook
71
+ move_file ( pre_commit_path_bak , pre_commit_path )
72
+
73
+ # Verify the commit was created
74
+ data = @lib . commit_data ( 'HEAD' )
75
+ assert_equal ( "commit with no verify and pre-commit file\n " , data [ 'message' ] )
76
+ end
77
+
47
78
def test_checkout
48
79
assert ( @lib . checkout ( 'test_checkout_b' , { :new_branch => true } ) )
49
80
assert ( @lib . checkout ( 'master' ) )
0 commit comments