git-si 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/git-si.gemspec +2 -1
- data/lib/git/si.rb +68 -369
- data/lib/git/si/actions.rb +153 -0
- data/lib/git/si/errors.rb +20 -0
- data/lib/git/si/git-control.rb +112 -0
- data/lib/git/si/git-ignore.rb +23 -0
- data/lib/git/si/svn-control.rb +135 -0
- data/lib/git/si/util.rb +304 -0
- data/lib/git/si/version.rb +12 -1
- data/spec/actions_spec.rb +356 -0
- data/spec/git-control_spec.rb +254 -0
- data/spec/git-ignore_spec.rb +37 -0
- data/spec/svn-control_spec.rb +391 -0
- data/spec/util_spec.rb +458 -0
- data/spec/version_spec.rb +17 -0
- metadata +40 -8
data/lib/git/si/util.rb
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
require "git/si/errors"
|
2
|
+
|
3
|
+
module Git
|
4
|
+
|
5
|
+
module Si
|
6
|
+
|
7
|
+
module Util
|
8
|
+
|
9
|
+
def did_last_command_succeed?
|
10
|
+
$?.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_command(command, options={})
|
14
|
+
output = ''
|
15
|
+
debug "run_command `#{command}`, options: #{options}"
|
16
|
+
if STDOUT.tty? and not @silent
|
17
|
+
output = run(command, options)
|
18
|
+
else
|
19
|
+
output = run(command, options.update(verbose: false, capture: true))
|
20
|
+
end
|
21
|
+
raise Git::Si::ShellError.new("There was an error while trying to run the command: #{command}. Look above for any errors.") if not options[:allow_errors] and not did_last_command_succeed?
|
22
|
+
return output
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_command_output(command, options={})
|
26
|
+
run_command(command, options.merge( capture: true ))
|
27
|
+
end
|
28
|
+
|
29
|
+
def batch_add_files_to_git( filenames )
|
30
|
+
filenames.each_slice(10) do |batch|
|
31
|
+
begin
|
32
|
+
run_command( Git::Si::GitControl.add_command( batch ) )
|
33
|
+
rescue
|
34
|
+
# try to batch the files but add them individually if there is an error
|
35
|
+
add_files_to_git( batch )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_files_to_git( filenames )
|
41
|
+
filenames.each do |filename|
|
42
|
+
begin
|
43
|
+
run_command( Git::Si::GitControl.add_command(filename) )
|
44
|
+
rescue
|
45
|
+
# errors here are not important enough to stop the whole process
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure
|
51
|
+
Git::Si::SvnControl.svn_binary = options[:svn]
|
52
|
+
Git::Si::GitControl.git_binary = options[:git]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Return the most recent svn revision number stored in git
|
56
|
+
def get_git_si_revision
|
57
|
+
info = get_command_output(Git::Si::GitControl.log_command('--pretty=%B'))
|
58
|
+
return Git::Si::GitControl.parse_last_svn_revision(info)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Return the most recent svn revision number
|
62
|
+
def get_svn_revision
|
63
|
+
svn_info = get_command_output(Git::Si::SvnControl.info_command)
|
64
|
+
return Git::Si::SvnControl.parse_last_revision(svn_info)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_svn_root
|
68
|
+
svn_info = get_command_output(Git::Si::SvnControl.info_command, {:allow_errors => true})
|
69
|
+
root_dir = Git::Si::SvnControl.parse_root_path(svn_info)
|
70
|
+
raise Git::Si::SvnError.new("Could not find the svn root directory.") unless root_dir
|
71
|
+
root_dir
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_local_branch
|
75
|
+
git_branches = get_command_output(Git::Si::GitControl.branch_command)
|
76
|
+
local_branch = Git::Si::GitControl.parse_current_branch(git_branches)
|
77
|
+
raise Git::Si::GitError.new("Could not find local branch name.") unless local_branch
|
78
|
+
return local_branch
|
79
|
+
end
|
80
|
+
|
81
|
+
def in_svn_root(&block)
|
82
|
+
root_dir = get_svn_root
|
83
|
+
notice_message "Changing directory to svn root: #{root_dir}"
|
84
|
+
Dir.chdir(root_dir) do
|
85
|
+
yield
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def on_local_branch(&block)
|
90
|
+
begin
|
91
|
+
in_svn_root do
|
92
|
+
yield
|
93
|
+
end
|
94
|
+
rescue Git::Si::GitSiError => err
|
95
|
+
error_message err
|
96
|
+
exit false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_mirror_branch
|
101
|
+
return 'MIRRORBRANCH'
|
102
|
+
end
|
103
|
+
|
104
|
+
def on_mirror_branch(&block)
|
105
|
+
local_branch = get_local_branch()
|
106
|
+
run_command( Git::Si::GitControl.checkout_command(get_mirror_branch) )
|
107
|
+
begin
|
108
|
+
in_svn_root do
|
109
|
+
yield
|
110
|
+
end
|
111
|
+
rescue Git::Si::GitSiError => err
|
112
|
+
error_message err
|
113
|
+
exit false
|
114
|
+
ensure
|
115
|
+
run_command( Git::Si::GitControl.checkout_command(local_branch) )
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def using_stderr(&block)
|
120
|
+
old_stdout = $stdout
|
121
|
+
$stdout = $stderr
|
122
|
+
@silent = true
|
123
|
+
begin
|
124
|
+
yield
|
125
|
+
ensure
|
126
|
+
$stdout = old_stdout
|
127
|
+
@silent = false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def success_message(message)
|
132
|
+
$stderr.puts set_color message, :green
|
133
|
+
end
|
134
|
+
|
135
|
+
def notice_message(message)
|
136
|
+
$stderr.puts set_color message, :yellow unless options[:quiet]
|
137
|
+
end
|
138
|
+
|
139
|
+
def error_message(message)
|
140
|
+
$stderr.puts set_color message, :red
|
141
|
+
end
|
142
|
+
|
143
|
+
def debug(message)
|
144
|
+
$stderr.puts message if options[:debug]
|
145
|
+
end
|
146
|
+
|
147
|
+
def do_revisions_differ
|
148
|
+
last_fetched_version = get_svn_revision()
|
149
|
+
last_rebased_version = get_git_si_revision()
|
150
|
+
|
151
|
+
if ! last_fetched_version or ! last_rebased_version
|
152
|
+
notice_message "Could not determine last git-si version information. This may be fine if you haven't used git-si before."
|
153
|
+
return
|
154
|
+
end
|
155
|
+
|
156
|
+
debug "comparing last fetched revision #{last_fetched_version} and last rebased revision #{last_rebased_version}"
|
157
|
+
|
158
|
+
if last_fetched_version > last_rebased_version
|
159
|
+
raise Git::Si::VersionError.new("This branch is out-of-date (svn revision #{last_rebased_version}; svn is at #{last_fetched_version}). You should do a git si rebase or git si pull.")
|
160
|
+
elsif last_fetched_version < last_rebased_version
|
161
|
+
return true if ask("This branch is newer (svn revision #{last_rebased_version}) than svn (rev #{last_fetched_version}). That can happen when svn changes have been made directly and may be fine. Do you want to continue? [Y/n] ", :green) =~ /\s*^n/i
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def print_colordiff(diff)
|
166
|
+
debug "print_colordiff"
|
167
|
+
if ! STDOUT.tty?
|
168
|
+
debug "print_colordiff returning without colorizing"
|
169
|
+
return say diff
|
170
|
+
end
|
171
|
+
debug "print_colordiff colorizing..."
|
172
|
+
diff.each_line do |line|
|
173
|
+
line.rstrip!
|
174
|
+
case line
|
175
|
+
when /^\+/, /^A/
|
176
|
+
line = set_color line, :green
|
177
|
+
when /^\-/, /^M/
|
178
|
+
line = set_color line, :red
|
179
|
+
when /^\?/
|
180
|
+
line = set_color line, :yellow
|
181
|
+
end
|
182
|
+
say line
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def are_there_git_changes?
|
187
|
+
Git::Si::GitControl.are_there_changes?( get_command_output( Git::Si::GitControl.status_command ) )
|
188
|
+
end
|
189
|
+
|
190
|
+
def create_git_repository
|
191
|
+
if File.exist? '.git'
|
192
|
+
notice_message "Looks like a git repository already exists here."
|
193
|
+
return false
|
194
|
+
end
|
195
|
+
notice_message "Initializing git repository"
|
196
|
+
run_command(Git::Si::GitControl.init_command, {:allow_errors => true})
|
197
|
+
raise Git::Si::GitError.new("Failed to initialize git repository. I'm not sure why. Check for any errors above.") unless did_last_command_succeed?
|
198
|
+
add_all_svn_files()
|
199
|
+
true
|
200
|
+
end
|
201
|
+
|
202
|
+
def create_gitignore
|
203
|
+
# add externals to gitignore
|
204
|
+
gitignore_patterns = Git::Si::GitIgnore.ignore_patterns
|
205
|
+
gitignore_patterns += Git::Si::SvnControl.parse_external_repos( get_command_output( Git::Si::SvnControl.status_command ) )
|
206
|
+
|
207
|
+
if not File.exist? '.gitignore'
|
208
|
+
notice_message "Creating gitignore file."
|
209
|
+
create_file('.gitignore', gitignore_patterns.join( "\n" ))
|
210
|
+
run_command( Git::Si::GitControl.add_command('.gitignore') )
|
211
|
+
return true
|
212
|
+
end
|
213
|
+
|
214
|
+
notice_message "Looks like a gitignore file already exists here."
|
215
|
+
missing_patterns = Git::Si::GitIgnore.get_missing_lines_from( File.readlines( '.gitignore' ), gitignore_patterns )
|
216
|
+
if not missing_patterns.empty?
|
217
|
+
using_stderr do
|
218
|
+
say "The .gitignore file is missing the following recommended patterns:\n#{missing_patterns.join( "\n" )}"
|
219
|
+
if yes?("Do you want to add them? [Y/n] ", :green)
|
220
|
+
append_to_file( '.gitignore', missing_patterns.join("\n") )
|
221
|
+
run_command( Git::Si::GitControl.add_command('.gitignore') )
|
222
|
+
return true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
false
|
227
|
+
end
|
228
|
+
|
229
|
+
def add_all_svn_files
|
230
|
+
notice_message "Adding all files present in the svn repository."
|
231
|
+
all_svn_files = Git::Si::SvnControl.parse_file_list( get_command_output( Git::Si::SvnControl.list_file_command ) )
|
232
|
+
raise Git::Si::GitSiError.new("No files could be found in the svn repository.") if all_svn_files.empty?
|
233
|
+
batch_add_files_to_git( all_svn_files )
|
234
|
+
end
|
235
|
+
|
236
|
+
def create_mirror_branch
|
237
|
+
begin
|
238
|
+
run_command( Git::Si::GitControl.show_branch_command(get_mirror_branch) )
|
239
|
+
rescue
|
240
|
+
# no problem. It just means the branch does not exist.
|
241
|
+
end
|
242
|
+
if did_last_command_succeed?
|
243
|
+
notice_message "Looks like the mirror branch already exists here."
|
244
|
+
else
|
245
|
+
notice_message "Creating mirror branch '#{get_mirror_branch}'."
|
246
|
+
run_command( Git::Si::GitControl.create_branch_command(get_mirror_branch) )
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def stash_local_changes
|
251
|
+
on_local_branch do
|
252
|
+
if are_there_git_changes?
|
253
|
+
notice_message "Preserving uncommitted changed files"
|
254
|
+
run_command( Git::Si::GitControl.stash_command )
|
255
|
+
return true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
false
|
259
|
+
end
|
260
|
+
|
261
|
+
def unstash_local_changes( did_stash_changes )
|
262
|
+
if did_stash_changes
|
263
|
+
notice_message "Restoring uncommitted changed files"
|
264
|
+
run_command( Git::Si::GitControl.unstash_command )
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def is_file_in_git?( filename )
|
269
|
+
not get_command_output( Git::Si::GitControl.list_file_command( filename ) ).empty?
|
270
|
+
end
|
271
|
+
|
272
|
+
def revert_files_to_svn_update( updated_files )
|
273
|
+
notice_message "Reverting any local changes in mirror branch"
|
274
|
+
# revert everything, but sometimes that doesn't work, so revert conflicts too.
|
275
|
+
run_command( Git::Si::SvnControl.revert_command )
|
276
|
+
Git::Si::SvnControl.parse_conflicted_files( updated_files ).each do |filename|
|
277
|
+
run_command( Git::Si::SvnControl.revert_command( filename ) )
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def delete_files_after_svn_update( updated_files )
|
282
|
+
# delete deleted files.
|
283
|
+
Git::Si::SvnControl.parse_deleted_files( updated_files ).each do |filename|
|
284
|
+
run_command( Git::Si::GitControl.delete_command( filename ) )
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def add_files_after_svn_update( updated_files )
|
289
|
+
notice_message "Updating mirror branch to match new data"
|
290
|
+
# add updated files
|
291
|
+
updated_files = Git::Si::SvnControl.parse_updated_files( updated_files )
|
292
|
+
batch_add_files_to_git( updated_files )
|
293
|
+
end
|
294
|
+
|
295
|
+
def delete_committed_branch( local_branch )
|
296
|
+
run_command( Git::Si::GitControl.checkout_command( 'master' ) )
|
297
|
+
do_rebase_action
|
298
|
+
run_command( Git::Si::GitControl.delete_branch_command( local_branch ) )
|
299
|
+
success_message "branch '#{local_branch}' deleted!"
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
data/lib/git/si/version.rb
CHANGED
@@ -0,0 +1,356 @@
|
|
1
|
+
require "git/si/util"
|
2
|
+
require "git/si/actions"
|
3
|
+
|
4
|
+
describe Git::Si::Actions do
|
5
|
+
let( :runner_spy ) { spy( 'runner_spy' ) }
|
6
|
+
let( :test_mixin_host ) {
|
7
|
+
Class.new do
|
8
|
+
include Git::Si::Util
|
9
|
+
include Git::Si::Actions
|
10
|
+
|
11
|
+
def initialize( spy )
|
12
|
+
@spy = spy
|
13
|
+
end
|
14
|
+
|
15
|
+
def say(toss)
|
16
|
+
end
|
17
|
+
|
18
|
+
def debug(toss)
|
19
|
+
end
|
20
|
+
|
21
|
+
def in_svn_root
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_mirror_branch
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message(toss)
|
30
|
+
end
|
31
|
+
|
32
|
+
def success_message(toss)
|
33
|
+
end
|
34
|
+
|
35
|
+
def notice_message(toss)
|
36
|
+
end
|
37
|
+
|
38
|
+
def did_last_command_succeed?
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_command( command, options={} )
|
43
|
+
@spy.run_command( command, options )
|
44
|
+
raise "test error" if command =~ /raise/
|
45
|
+
"testing run_command"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
}
|
49
|
+
|
50
|
+
let( :svn_status_output ) { "Z foobar
|
51
|
+
X foobar
|
52
|
+
? .git
|
53
|
+
M foobar.git
|
54
|
+
M foobar.swp
|
55
|
+
M barfoo
|
56
|
+
A something
|
57
|
+
D something else
|
58
|
+
? whatever
|
59
|
+
" }
|
60
|
+
|
61
|
+
let( :svn_update_output ) { "
|
62
|
+
Restored 'bin/tests/importantthing'
|
63
|
+
A bin/tests/foobar
|
64
|
+
U bin/tests/api/goobar
|
65
|
+
G bin/tests/api/special
|
66
|
+
U bin/tests/api/anotherfile
|
67
|
+
A bin/tests/barfoo
|
68
|
+
? unknownfile.md
|
69
|
+
D byefile
|
70
|
+
C myimage.png
|
71
|
+
D badjs.js
|
72
|
+
C something/javascript.js
|
73
|
+
A something/newjs.js
|
74
|
+
C css/_base.scss
|
75
|
+
Updated to revision 113333.
|
76
|
+
" }
|
77
|
+
|
78
|
+
subject { test_mixin_host.new( runner_spy ) }
|
79
|
+
|
80
|
+
describe "#do_status_action" do
|
81
|
+
before do
|
82
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
83
|
+
end
|
84
|
+
|
85
|
+
it "sends status output to print_colordiff" do
|
86
|
+
data = "Z foobar
|
87
|
+
M something else"
|
88
|
+
allow( subject ).to receive( :run_command ).with( /svn status/, any_args ).and_return( data )
|
89
|
+
allow( subject ).to receive( :print_colordiff )
|
90
|
+
expect( subject ).to receive( :print_colordiff ).with( data )
|
91
|
+
subject.do_status_action
|
92
|
+
end
|
93
|
+
|
94
|
+
it "calls svn status with passed arguments" do
|
95
|
+
expect( subject ).to receive( :run_command ).with( /svn status .+ foobar barfoo/, any_args )
|
96
|
+
subject.do_status_action( [ 'foobar', 'barfoo' ] )
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#do_diff_action" do
|
101
|
+
before do
|
102
|
+
allow( subject ).to receive( :do_readd_action )
|
103
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
104
|
+
end
|
105
|
+
|
106
|
+
it "calls do_revisions_differ" do
|
107
|
+
allow( subject ).to receive( :do_revisions_differ )
|
108
|
+
expect( subject ).to receive( :do_revisions_differ ).once
|
109
|
+
subject.do_diff_action
|
110
|
+
end
|
111
|
+
|
112
|
+
it "calls the readd action" do
|
113
|
+
expect( subject ).to receive( :do_readd_action ).once
|
114
|
+
subject.do_diff_action
|
115
|
+
end
|
116
|
+
|
117
|
+
it "sends diff output to print_colordiff" do
|
118
|
+
data = "+ foobar
|
119
|
+
- something else"
|
120
|
+
allow( subject ).to receive( :run_command ).with( /svn diff/, any_args ).and_return( data )
|
121
|
+
allow( subject ).to receive( :print_colordiff )
|
122
|
+
expect( subject ).to receive( :print_colordiff ).with( data )
|
123
|
+
subject.do_diff_action
|
124
|
+
end
|
125
|
+
|
126
|
+
it "calls svn diff with passed arguments" do
|
127
|
+
expect( subject ).to receive( :run_command ).with( /svn diff.+foobar barfoo/, any_args )
|
128
|
+
subject.do_diff_action( [ 'foobar', 'barfoo' ] )
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#do_add_action" do
|
133
|
+
it "calls git add with the passed arguments" do
|
134
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
135
|
+
expect( subject ).to receive( :run_command ).with( /git add.+foobar barfoo/ )
|
136
|
+
subject.do_add_action( [ 'foobar', 'barfoo' ] )
|
137
|
+
end
|
138
|
+
|
139
|
+
it "calls svn add with the passed arguments" do
|
140
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
141
|
+
expect( subject ).to receive( :run_command ).with( /svn add.+foobar barfoo/ )
|
142
|
+
subject.do_add_action( [ 'foobar', 'barfoo' ] )
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#do_fetch_action" do
|
147
|
+
it "calls stash_local_changes" do
|
148
|
+
expect( subject ).to receive( :stash_local_changes ).once
|
149
|
+
subject.do_fetch_action
|
150
|
+
end
|
151
|
+
|
152
|
+
it "calls svn update" do
|
153
|
+
expect( runner_spy ).to receive( :run_command ).with( /svn up/, any_args )
|
154
|
+
subject.do_fetch_action
|
155
|
+
end
|
156
|
+
|
157
|
+
it "calls revert_files_to_svn_update with update output" do
|
158
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
159
|
+
allow( subject ).to receive( :run_command ).with( /svn up/, any_args ).and_return( svn_update_output )
|
160
|
+
expect( subject ).to receive( :revert_files_to_svn_update ).with( svn_update_output )
|
161
|
+
subject.do_fetch_action
|
162
|
+
end
|
163
|
+
|
164
|
+
it "calls delete_files_after_svn_update with update output" do
|
165
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
166
|
+
allow( subject ).to receive( :run_command ).with( /svn up/, any_args ).and_return( svn_update_output )
|
167
|
+
expect( subject ).to receive( :delete_files_after_svn_update ).with( svn_update_output )
|
168
|
+
subject.do_fetch_action
|
169
|
+
end
|
170
|
+
|
171
|
+
it "calls add_files_after_svn_update with update output" do
|
172
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
173
|
+
allow( subject ).to receive( :run_command ).with( /svn up/, any_args ).and_return( svn_update_output )
|
174
|
+
expect( subject ).to receive( :add_files_after_svn_update ).with( svn_update_output )
|
175
|
+
subject.do_fetch_action
|
176
|
+
end
|
177
|
+
|
178
|
+
it "makes a git commit with the svn revision" do
|
179
|
+
allow( subject ).to receive( :get_svn_revision ).and_return( '1012' )
|
180
|
+
expect( runner_spy ).to receive( :run_command ).with( /git commit .+1012/, any_args )
|
181
|
+
subject.do_fetch_action
|
182
|
+
end
|
183
|
+
|
184
|
+
it "calls unstash_local_changes with true if changes were stashed" do
|
185
|
+
allow( subject ).to receive( :stash_local_changes ).and_return( true )
|
186
|
+
expect( subject ).to receive( :unstash_local_changes ).with( true ).once
|
187
|
+
subject.do_fetch_action
|
188
|
+
end
|
189
|
+
|
190
|
+
it "calls unstash_local_changes with false if no changes were stashed" do
|
191
|
+
allow( subject ).to receive( :stash_local_changes ).and_return( false )
|
192
|
+
expect( subject ).to receive( :unstash_local_changes ).with( false ).once
|
193
|
+
subject.do_fetch_action
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "#do_rebase_action" do
|
198
|
+
it "calls stash_local_changes" do
|
199
|
+
expect( subject ).to receive( :stash_local_changes ).once
|
200
|
+
subject.do_rebase_action
|
201
|
+
end
|
202
|
+
|
203
|
+
it "calls unstash_local_changes with true if changes were stashed" do
|
204
|
+
allow( subject ).to receive( :stash_local_changes ).and_return( true )
|
205
|
+
expect( subject ).to receive( :unstash_local_changes ).with( true ).once
|
206
|
+
subject.do_rebase_action
|
207
|
+
end
|
208
|
+
|
209
|
+
it "calls unstash_local_changes with false if no changes were stashed" do
|
210
|
+
allow( subject ).to receive( :stash_local_changes ).and_return( false )
|
211
|
+
expect( subject ).to receive( :unstash_local_changes ).with( false ).once
|
212
|
+
subject.do_rebase_action
|
213
|
+
end
|
214
|
+
|
215
|
+
it "calls rebase command with the mirror branch" do
|
216
|
+
allow( subject ).to receive( :get_mirror_branch ).and_return( 'testbranch' )
|
217
|
+
expect( runner_spy ).to receive( :run_command ).with( /git rebase .+testbranch/, any_args )
|
218
|
+
subject.do_rebase_action
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "#do_pull_action" do
|
223
|
+
it "calls fetch action" do
|
224
|
+
expect( subject ).to receive( :do_fetch_action ).once
|
225
|
+
subject.do_pull_action
|
226
|
+
end
|
227
|
+
|
228
|
+
it "calls rebase action" do
|
229
|
+
expect( subject ).to receive( :do_rebase_action ).once
|
230
|
+
subject.do_pull_action
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "#do_commit_action" do
|
235
|
+
before do
|
236
|
+
allow( subject ).to receive( :get_local_branch ).and_return( 'testbranch' )
|
237
|
+
allow( subject ).to receive( :yes? ).and_return( 'y' )
|
238
|
+
end
|
239
|
+
|
240
|
+
it "calls the readd action" do
|
241
|
+
expect( subject ).to receive( :do_readd_action ).once
|
242
|
+
subject.do_commit_action
|
243
|
+
end
|
244
|
+
|
245
|
+
it "runs a commit if the local branch is not master" do
|
246
|
+
expect( runner_spy ).to receive( :run_command ).with( /svn commit/, any_args )
|
247
|
+
subject.do_commit_action
|
248
|
+
end
|
249
|
+
|
250
|
+
it "does not run a commit if the local branch is master" do
|
251
|
+
allow( subject ).to receive( :get_local_branch ).and_return( 'master' )
|
252
|
+
expect( runner_spy ).not_to receive( :run_command ).with( /svn commit/, any_args )
|
253
|
+
subject.do_commit_action
|
254
|
+
end
|
255
|
+
|
256
|
+
it "does not run a commit if there are git changes pending" do
|
257
|
+
allow( subject ).to receive( :are_there_git_changes? ).and_return( true )
|
258
|
+
expect( runner_spy ).not_to receive( :run_command ).with( /svn commit/, any_args )
|
259
|
+
expect { subject.do_commit_action }.to raise_error
|
260
|
+
end
|
261
|
+
|
262
|
+
it "does not run a commit if there are no svn changes" do
|
263
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
264
|
+
allow( subject ).to receive( :run_command ).with( /svn diff/, any_args ).and_return( '' )
|
265
|
+
expect( runner_spy ).not_to receive( :run_command ).with( /svn commit/, any_args )
|
266
|
+
expect { subject.do_commit_action }.to raise_error
|
267
|
+
end
|
268
|
+
|
269
|
+
it "calls delete_committed_branch" do
|
270
|
+
expect( subject ).to receive( :delete_committed_branch ).once
|
271
|
+
subject.do_commit_action
|
272
|
+
end
|
273
|
+
|
274
|
+
it "calls the fetch action" do
|
275
|
+
expect( subject ).to receive( :do_fetch_action ).once
|
276
|
+
subject.do_commit_action
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "#do_readd_action" do
|
281
|
+
before do
|
282
|
+
allow( subject ).to receive( :yes? ).and_return( 'y' )
|
283
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
284
|
+
allow( subject ).to receive( :run_command ).with( /svn status/, any_args ).and_return( svn_status_output )
|
285
|
+
end
|
286
|
+
|
287
|
+
it "does not run svn add if there are no git files unknown to svn" do
|
288
|
+
allow( subject ).to receive( :is_file_in_git? ).and_return( false )
|
289
|
+
expect( subject ).not_to receive( :run_command ).with( /svn add/, any_args )
|
290
|
+
subject.do_readd_action
|
291
|
+
end
|
292
|
+
|
293
|
+
it "runs svn add if there are git files unknown to svn" do
|
294
|
+
allow( subject ).to receive( :is_file_in_git? ).and_return( true )
|
295
|
+
expect( subject ).to receive( :run_command ).with( /svn add.+whatever/, any_args )
|
296
|
+
subject.do_readd_action
|
297
|
+
end
|
298
|
+
|
299
|
+
it "includes the correct files in the svn add command" do
|
300
|
+
allow( subject ).to receive( :is_file_in_git? ).and_return( false )
|
301
|
+
allow( subject ).to receive( :is_file_in_git? ).with( 'whatever' ).and_return( true )
|
302
|
+
expect( subject ).to receive( :run_command ).with( /svn add.+whatever/, any_args )
|
303
|
+
subject.do_readd_action
|
304
|
+
end
|
305
|
+
|
306
|
+
it "does not include the incorrect files in the svn add command" do
|
307
|
+
allow( subject ).to receive( :is_file_in_git? ).and_return( true )
|
308
|
+
allow( subject ).to receive( :is_file_in_git? ).with( 'whatever' ).and_return( false )
|
309
|
+
expect( subject ).not_to receive( :run_command ).with( /svn add.+something/, any_args )
|
310
|
+
subject.do_readd_action
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "#do_init_action" do
|
315
|
+
before do
|
316
|
+
allow( subject ).to receive( :create_file )
|
317
|
+
allow( subject ).to receive( :append_to_file )
|
318
|
+
allow( subject ).to receive( :yes? ).and_return( 'y' )
|
319
|
+
allow( subject ).to receive( :run_command ).and_return( '' )
|
320
|
+
end
|
321
|
+
|
322
|
+
it "raises an error if not in an svn repo" do
|
323
|
+
allow( subject ).to receive( :did_last_command_succeed? ).and_return( false )
|
324
|
+
expect { subject.do_init_action }.to raise_error
|
325
|
+
end
|
326
|
+
|
327
|
+
it "runs an svn update" do
|
328
|
+
expect( subject ).to receive( :run_command ).with( /svn up/, any_args )
|
329
|
+
subject.do_init_action
|
330
|
+
end
|
331
|
+
|
332
|
+
it "calls create_git_repository" do
|
333
|
+
expect( subject ).to receive( :create_git_repository ).once
|
334
|
+
subject.do_init_action
|
335
|
+
end
|
336
|
+
|
337
|
+
it "calls create_gitignore" do
|
338
|
+
expect( subject ).to receive( :create_gitignore ).once
|
339
|
+
subject.do_init_action
|
340
|
+
end
|
341
|
+
|
342
|
+
it "calls create_mirror_branch" do
|
343
|
+
expect( subject ).to receive( :create_mirror_branch ).once
|
344
|
+
subject.do_init_action
|
345
|
+
end
|
346
|
+
|
347
|
+
it "runs git commit with the initial commit message" do
|
348
|
+
allow( subject ).to receive( :get_svn_revision ).and_return( '1012' )
|
349
|
+
expect( subject ).to receive( :run_command ).with( /git commit.+1012/, any_args )
|
350
|
+
subject.do_init_action
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
|