File tree 3 files changed +26
-1
lines changed
spec/overcommit/hook_context
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ class GitConfigError < StandardError; end
11
11
# Raised when there was a problem reading submodule information for a repo.
12
12
class GitSubmoduleError < StandardError ; end
13
13
14
+ # Raised when there was a problem reading git revision information with `rev-list`.
15
+ class GitRevListError < StandardError ; end
16
+
14
17
# Raised when a {HookContext} is unable to setup the environment before a run.
15
18
class HookSetupFailed < StandardError ; end
16
19
Original file line number Diff line number Diff line change @@ -41,7 +41,14 @@ def to_s
41
41
private
42
42
43
43
def overwritten_commits
44
- `git rev-list #{ remote_sha1 } ^#{ local_sha1 } ` . split ( "\n " )
44
+ return @overwritten_commits if defined? @overwritten_commits
45
+ result = Overcommit ::Subprocess . spawn ( %W[ git rev-list #{ remote_sha1 } ^#{ local_sha1 } ] )
46
+ if result . success?
47
+ result . stdout . split ( "\n " )
48
+ else
49
+ raise Overcommit ::Exceptions ::GitRevListError ,
50
+ "Unable to check if commits on the remote ref will be overwritten: #{ result . stderr } "
51
+ end
45
52
end
46
53
end
47
54
end
Original file line number Diff line number Diff line change 89
89
90
90
it { should == true }
91
91
end
92
+
93
+ context 'when remote ref head does not exist locally' do
94
+ let ( :git_error_msg ) { "fatal: bad object #{ remote_sha1 } " }
95
+
96
+ before do
97
+ pushed_ref . stub ( created? : false , deleted? : false )
98
+ result = double ( success? : false , stderr : git_error_msg )
99
+ Overcommit ::Subprocess . stub ( :spawn ) . and_return ( result )
100
+ end
101
+
102
+ it 'should raise' do
103
+ expect { subject } . to raise_error ( Overcommit ::Exceptions ::GitRevListError ,
104
+ /#{ git_error_msg } / )
105
+ end
106
+ end
92
107
end
93
108
94
109
describe '#created?' do
You can’t perform that action at this time.
0 commit comments