File tree 3 files changed +32
-7
lines changed
spec/overcommit/hook_context
3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,6 @@ module Overcommit::Hook::PostCommit
5
5
class Base < Overcommit ::Hook ::Base
6
6
extend Forwardable
7
7
8
- def_delegators :@context , :modified_lines_in_file
8
+ def_delegators :@context , :modified_lines_in_file , :initial_commit?
9
9
end
10
10
end
Original file line number Diff line number Diff line change @@ -19,13 +19,11 @@ def modified_lines_in_file(file)
19
19
Overcommit ::GitRepo . extract_modified_lines ( file , subcmd : subcmd )
20
20
end
21
21
22
- private
23
-
24
- # Returns whether a previous commit exists on the current git branch.
22
+ # Returns whether the current git branch has only one commit.
25
23
# @return [true,false]
26
- def previous_commit ?
27
- return @previous_commit unless @previous_commit . nil?
28
- @previous_commit = Overcommit ::Utils . execute ( %w[ git rev-parse HEAD~ ] ) . success?
24
+ def initial_commit ?
25
+ return @initial_commit unless @initial_commit . nil?
26
+ @initial_commit = ! Overcommit ::Utils . execute ( %w[ git rev-parse HEAD~ ] ) . success?
29
27
end
30
28
end
31
29
end
Original file line number Diff line number Diff line change 113
113
it { should == Set . new ( 1 ..3 ) }
114
114
end
115
115
end
116
+
117
+ describe '#initial_commit?' do
118
+ subject { context . initial_commit? }
119
+
120
+ context 'when a previous commit exists' do
121
+ around do |example |
122
+ repo do
123
+ `git commit --allow-empty -m "Initial commit"`
124
+ `git commit --allow-empty -m "Another commit"`
125
+ example . run
126
+ end
127
+ end
128
+
129
+ it { should == false }
130
+ end
131
+
132
+ context 'when no previous commit exists' do
133
+ around do |example |
134
+ repo do
135
+ `git commit --allow-empty -m "Initial commit"`
136
+ example . run
137
+ end
138
+ end
139
+
140
+ it { should == true }
141
+ end
142
+ end
116
143
end
You can’t perform that action at this time.
0 commit comments