git_hook-pre_receive 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -15,10 +15,10 @@ module Git
|
|
15
15
|
if old_sha1 == '0' * 40
|
16
16
|
result = Git::Command.diff_tree(new_sha1)
|
17
17
|
result.delete_at(0)
|
18
|
-
result.collect { |l| File.new(l) }
|
18
|
+
result.delete_if { |l| l['0000000... D'] != nil }.collect { |l| File.new(l) }
|
19
19
|
else
|
20
20
|
result = Git::Command.diff(old_sha1, new_sha1)
|
21
|
-
result.collect { |l| File.new(l) }
|
21
|
+
result.delete_if { |l| l['0000000... D'] != nil }.collect { |l| File.new(l) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/spec/command_spec.rb
CHANGED
@@ -79,6 +79,20 @@ describe Command do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
context '#rm_r' do
|
83
|
+
it 'deletes files' do
|
84
|
+
git_init(git_repo)
|
85
|
+
|
86
|
+
create_file(File.join(git_repo, 'file.txt'))
|
87
|
+
git_add(git_repo, 'file.txt')
|
88
|
+
git_commit(git_repo)
|
89
|
+
|
90
|
+
Dir.chdir(::File.join(working_directory, git_repo)) do
|
91
|
+
expect(Command.rm_r('file.txt').last).to include('file.txt')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
82
96
|
context '#diff' do
|
83
97
|
it 'diff values' do
|
84
98
|
git_init(git_repo)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
2
4
|
describe PreReceiveHookParser do
|
3
5
|
let(:git_repo) { 'git_repo' }
|
4
6
|
|
@@ -60,5 +62,27 @@ describe PreReceiveHookParser do
|
|
60
62
|
expect(parser.files.collect { |f| f.name }).to eq(%w{dir/file.txt})
|
61
63
|
end
|
62
64
|
end
|
65
|
+
|
66
|
+
it 'handles deleted directories as well' do
|
67
|
+
git_init(git_repo)
|
68
|
+
|
69
|
+
create_file(File.join(git_repo, 'dir/file.txt'), 'file to delete')
|
70
|
+
git_add(git_repo, 'dir/file.txt')
|
71
|
+
git_commit(git_repo)
|
72
|
+
|
73
|
+
git_rm_r(git_repo, 'dir/file.txt')
|
74
|
+
|
75
|
+
create_file(File.join(git_repo, 'file1.txt'), 'new file')
|
76
|
+
git_add(git_repo, 'file1.txt')
|
77
|
+
|
78
|
+
git_commit(git_repo, 'deleted objects')
|
79
|
+
|
80
|
+
commit = git_show(git_repo, nil).first.split(" ")[1]
|
81
|
+
|
82
|
+
Dir.chdir(::File.join(working_directory, git_repo)) do
|
83
|
+
parser = PreReceiveHookParser.new("#{commit}^ #{commit} /ref/asdf/asdf")
|
84
|
+
expect(parser.files.collect { |f| f.name }).to eq(%w{file1.txt})
|
85
|
+
end
|
86
|
+
end
|
63
87
|
end
|
64
88
|
end
|
data/spec/support/git.rb
CHANGED