git-process 0.9.1.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +56 -0
- data/LICENSE +22 -0
- data/README.md +80 -0
- data/Rakefile +16 -0
- data/bin/git-new-fb +21 -0
- data/bin/git-pull-request +21 -0
- data/bin/git-sync +21 -0
- data/bin/git-to-master +21 -0
- data/git-process.gemspec +21 -0
- data/lib/git-process/abstract-error-builder.rb +46 -0
- data/lib/git-process/git-abstract-merge-error-builder.rb +115 -0
- data/lib/git-process/git-branch.rb +86 -0
- data/lib/git-process/git-branches.rb +53 -0
- data/lib/git-process/git-lib.rb +413 -0
- data/lib/git-process/git-merge-error.rb +31 -0
- data/lib/git-process/git-new-fb-options.rb +34 -0
- data/lib/git-process/git-process-error.rb +10 -0
- data/lib/git-process/git-process-options.rb +82 -0
- data/lib/git-process/git-process.rb +194 -0
- data/lib/git-process/git-pull-request-options.rb +42 -0
- data/lib/git-process/git-rebase-error.rb +31 -0
- data/lib/git-process/git-status.rb +72 -0
- data/lib/git-process/git-sync-options.rb +34 -0
- data/lib/git-process/git-to-master-options.rb +18 -0
- data/lib/git-process/github-client.rb +73 -0
- data/lib/git-process/github-service.rb +156 -0
- data/lib/git-process/parked-changes-error.rb +32 -0
- data/lib/git-process/pull-request.rb +38 -0
- data/lib/git-process/uncommitted-changes-error.rb +15 -0
- data/lib/git-process/version.rb +12 -0
- data/spec/FileHelpers.rb +18 -0
- data/spec/GitRepoHelper.rb +86 -0
- data/spec/git-abstract-merge-error-builder_spec.rb +113 -0
- data/spec/git-lib_spec.rb +118 -0
- data/spec/git-process_spec.rb +328 -0
- data/spec/git-status_spec.rb +101 -0
- data/spec/github-service_spec.rb +209 -0
- data/spec/pull-request_spec.rb +57 -0
- data/spec/spec_helper.rb +1 -0
- metadata +133 -0
data/spec/FileHelpers.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
module FileHelpers
|
5
|
+
TEST_DIR = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
def dir_files(dir)
|
8
|
+
Dir.entries(dir).grep(/^[^.]/)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def compare_files(file1name, file2name)
|
13
|
+
str1 = IO.read(file1name)
|
14
|
+
str2 = IO.read(file2name)
|
15
|
+
str1.should == str2
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'FileHelpers'
|
2
|
+
require 'git-lib'
|
3
|
+
|
4
|
+
module GitRepoHelper
|
5
|
+
|
6
|
+
|
7
|
+
def gitlib
|
8
|
+
@gitlib ||= Git::GitLib.new(tmpdir, :log_level => log_level)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def gitprocess
|
13
|
+
@gitprocess ||= Git::Process.new(nil, gitlib)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def tmpdir
|
18
|
+
@tmpdir ||= Dir.mktmpdir
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def commit_count
|
23
|
+
gitlib.log_count
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def log_level
|
28
|
+
Logger::ERROR
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def logger
|
33
|
+
gitlib.logger
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def create_files(file_names)
|
38
|
+
Dir.chdir(gitlib.workdir) do |dir|
|
39
|
+
file_names.each do |fn|
|
40
|
+
gitlib.logger.debug {"Creating #{dir}/#{fn}"}
|
41
|
+
FileUtils.touch fn
|
42
|
+
end
|
43
|
+
end
|
44
|
+
gitlib.add(file_names)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def change_file(filename, contents, lib = gitlib)
|
49
|
+
Dir.chdir(lib.workdir) do
|
50
|
+
File.open(filename, 'w') {|f| f.puts contents}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def change_file_and_add(filename, contents, lib = gitlib)
|
56
|
+
change_file(filename, contents, lib)
|
57
|
+
lib.add(filename)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def change_file_and_commit(filename, contents, lib = gitlib)
|
62
|
+
change_file_and_add(filename, contents, lib)
|
63
|
+
lib.commit("#{filename} - #{contents}")
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def clone(branch='master', &block)
|
68
|
+
td = Dir.mktmpdir
|
69
|
+
gl = Git::GitLib.new(td, :log_level => log_level)
|
70
|
+
gl.add_remote('origin', "file://#{tmpdir}")
|
71
|
+
gl.fetch
|
72
|
+
gl.checkout(branch, :new_branch => "origin/#{branch}")
|
73
|
+
if block_given?
|
74
|
+
begin
|
75
|
+
block.arity < 1 ? gl.instance_eval(&block) : block.call(gl)
|
76
|
+
rescue => exp
|
77
|
+
rm_rf(gl.workdir)
|
78
|
+
raise exp
|
79
|
+
end
|
80
|
+
nil
|
81
|
+
else
|
82
|
+
gl
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'git-abstract-merge-error-builder'
|
2
|
+
|
3
|
+
describe Git::AbstractMergeErrorBuilder do
|
4
|
+
|
5
|
+
def builder
|
6
|
+
unless @builder
|
7
|
+
@builder = Object.new
|
8
|
+
@builder.extend(Git::AbstractMergeErrorBuilder)
|
9
|
+
@builder.stub(:lib).and_return(lib)
|
10
|
+
@builder.stub(:continue_command).and_return(nil)
|
11
|
+
@builder.stub(:error_message).and_return('')
|
12
|
+
end
|
13
|
+
@builder
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def lib
|
18
|
+
unless @lib
|
19
|
+
@lib = double('lib')
|
20
|
+
@lib.stub(:rerere_enabled?).and_return(true)
|
21
|
+
@lib.stub(:rerere_autoupdate?).and_return(true)
|
22
|
+
@lib.stub(:status).and_return(status)
|
23
|
+
end
|
24
|
+
@lib
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def status
|
29
|
+
unless @status
|
30
|
+
@status = double('status')
|
31
|
+
@status.stub(:unmerged).and_return([])
|
32
|
+
@status.stub(:modified).and_return([])
|
33
|
+
@status.stub(:added).and_return([])
|
34
|
+
end
|
35
|
+
@status
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def match_commands(expected)
|
40
|
+
commands = builder.commands
|
41
|
+
expected.each do |e|
|
42
|
+
commands.slice!(0).should == e
|
43
|
+
end
|
44
|
+
commands.should be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it "merged with rerere.enabled false" do
|
49
|
+
lib.stub(:rerere_enabled?).and_return(false)
|
50
|
+
status.stub(:unmerged).and_return(['a', 'b c'])
|
51
|
+
status.stub(:modified).and_return(['a', 'b c'])
|
52
|
+
|
53
|
+
builder.resolved_files.should == []
|
54
|
+
builder.unresolved_files.should == ['a', 'b c']
|
55
|
+
match_commands [
|
56
|
+
'git config --global rerere.enabled true',
|
57
|
+
'git mergetool a b\ c',
|
58
|
+
'# Verify \'a\' merged correctly.',
|
59
|
+
'# Verify \'b c\' merged correctly.',
|
60
|
+
'git add a b\ c',
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it "merged with rerere.enabled true and auto-handled AND autoupdated a file" do
|
66
|
+
status.stub(:unmerged).and_return(['a', 'b c'])
|
67
|
+
status.stub(:modified).and_return(['a', 'b c'])
|
68
|
+
builder.stub(:error_message).and_return("\nResolved 'a' using previous resolution.\n")
|
69
|
+
|
70
|
+
builder.resolved_files.should == ['a']
|
71
|
+
builder.unresolved_files.should == ['b c']
|
72
|
+
match_commands [
|
73
|
+
'# Verify that \'rerere\' did the right thing for \'a\'.',
|
74
|
+
'git mergetool b\ c',
|
75
|
+
'# Verify \'b c\' merged correctly.',
|
76
|
+
'git add b\ c',
|
77
|
+
]
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
it "merged with rerere.enabled true and auto-handled and not autoupdated a file" do
|
82
|
+
lib.stub(:rerere_autoupdate?).and_return(false)
|
83
|
+
status.stub(:unmerged).and_return(['a', 'b c'])
|
84
|
+
status.stub(:modified).and_return(['a', 'b c'])
|
85
|
+
builder.stub(:error_message).and_return("\nResolved 'a' using previous resolution.\n")
|
86
|
+
|
87
|
+
builder.resolved_files.should == ['a']
|
88
|
+
builder.unresolved_files.should == ['b c']
|
89
|
+
match_commands [
|
90
|
+
'# Verify that \'rerere\' did the right thing for \'a\'.',
|
91
|
+
'git add a',
|
92
|
+
'git mergetool b\ c',
|
93
|
+
'# Verify \'b c\' merged correctly.',
|
94
|
+
'git add b\ c',
|
95
|
+
]
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
it "merged with a file added in both branches" do
|
100
|
+
lib.stub(:rerere_autoupdate?).and_return(false)
|
101
|
+
status.stub(:unmerged).and_return(['a'])
|
102
|
+
status.stub(:modified).and_return(['b'])
|
103
|
+
status.stub(:added).and_return(['a', 'c'])
|
104
|
+
|
105
|
+
builder.resolved_files.should == []
|
106
|
+
builder.unresolved_files.should == ['a']
|
107
|
+
match_commands [
|
108
|
+
'# \'a\' was added in both branches; Fix the conflict.',
|
109
|
+
'git add a',
|
110
|
+
]
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'git-lib'
|
2
|
+
require 'GitRepoHelper'
|
3
|
+
|
4
|
+
describe Git::GitLib do
|
5
|
+
|
6
|
+
describe "branches" do
|
7
|
+
include GitRepoHelper
|
8
|
+
|
9
|
+
it "list all the branches" do
|
10
|
+
create_files(['.gitignore'])
|
11
|
+
gitlib.commit('initial')
|
12
|
+
|
13
|
+
gitlib.branch('ba', :base_branch => 'master')
|
14
|
+
gitlib.branch('bb', :base_branch => 'master')
|
15
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
16
|
+
|
17
|
+
gitlib.branches.names.should == ['ba', 'bb', 'master', 'origin/master']
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
describe "branch" do
|
24
|
+
attr_reader :lib
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@lib = Git::GitLib.new(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it "should create a branch with default base" do
|
32
|
+
lib.stub(:command).with(:branch, ['test_branch', 'master'])
|
33
|
+
lib.branch('test_branch')
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
it "should create a branch with explicit base" do
|
38
|
+
lib.stub(:command).with(:branch, ['test_branch', 'other_branch'])
|
39
|
+
lib.branch('test_branch', :base_branch => 'other_branch')
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
it "should delete a branch without force" do
|
44
|
+
lib.stub(:command).with(:branch, ['-d', 'test_branch'])
|
45
|
+
lib.branch('test_branch', :delete => true)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
it "should delete a branch with force" do
|
50
|
+
lib.stub(:command).with(:branch, ['-D', 'test_branch'])
|
51
|
+
lib.branch('test_branch', :delete => true, :force => true)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
describe "push" do
|
58
|
+
attr_reader :lib
|
59
|
+
|
60
|
+
before(:each) do
|
61
|
+
@lib = Git::GitLib.new(nil, :git => double('git'))
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def log_level
|
66
|
+
Logger::ERROR
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
it "should push local branch to remote" do
|
71
|
+
lib.should_receive(:command).with(:push, ['remote', 'local_branch:test_branch'])
|
72
|
+
|
73
|
+
lib.push('remote', 'local_branch', 'test_branch')
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
it "should push current branch to remote" do
|
78
|
+
lib.stub(:command).with(:branch, ['-a', '--no-color']).and_return("* my_branch\n")
|
79
|
+
lib.should_receive(:command).with(:push, ['remote', 'my_branch:my_branch'])
|
80
|
+
|
81
|
+
lib.push('remote', 'my_branch', nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
it "should remove named branch on remote" do
|
86
|
+
lib.should_receive(:command).with(:push, ['remote', '--delete', 'my_branch'])
|
87
|
+
|
88
|
+
lib.push('remote', 'my_branch', nil, :delete => true)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it "should remove current branch on remote" do
|
93
|
+
lib.should_receive(:command).with(:push, ['remote', '--delete', 'my_branch'])
|
94
|
+
|
95
|
+
lib.push('remote', nil, nil, :delete => 'my_branch')
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# it "should create a branch with explicit base" do
|
100
|
+
# lib.stub(:command).with(:branch, ['test_branch', 'other_branch'])
|
101
|
+
# lib.branch('test_branch', :base_branch => 'other_branch')
|
102
|
+
# end
|
103
|
+
|
104
|
+
|
105
|
+
# it "should delete a branch without force" do
|
106
|
+
# lib.stub(:command).with(:branch, ['-d', 'test_branch'])
|
107
|
+
# lib.branch('test_branch', :delete => true)
|
108
|
+
# end
|
109
|
+
|
110
|
+
|
111
|
+
# it "should delete a branch with force" do
|
112
|
+
# lib.stub(:command).with(:branch, ['-D', 'test_branch'])
|
113
|
+
# lib.branch('test_branch', :delete => true, :force => true)
|
114
|
+
# end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,328 @@
|
|
1
|
+
require 'git-process'
|
2
|
+
require 'GitRepoHelper'
|
3
|
+
|
4
|
+
describe Git::Process do
|
5
|
+
include GitRepoHelper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
create_files(['.gitignore'])
|
9
|
+
gitlib.commit('initial')
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
rm_rf(tmpdir)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe "rebase to master" do
|
19
|
+
|
20
|
+
def log_level
|
21
|
+
Logger::ERROR
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
it "should work easily for a simple rebase" do
|
26
|
+
gitlib.checkout('fb', :new_branch => 'master')
|
27
|
+
change_file_and_commit('a', '')
|
28
|
+
|
29
|
+
commit_count.should == 2
|
30
|
+
|
31
|
+
gitlib.checkout('master')
|
32
|
+
change_file_and_commit('b', '')
|
33
|
+
|
34
|
+
gitlib.checkout('fb')
|
35
|
+
|
36
|
+
gitprocess.rebase_to_master
|
37
|
+
|
38
|
+
commit_count.should == 3
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it "should work for a rebase after a rerere merge" do
|
43
|
+
# Make sure rerere is enabled
|
44
|
+
gitlib.rerere_enabled(true, false)
|
45
|
+
gitlib.rerere_autoupdate(false, false)
|
46
|
+
|
47
|
+
# Create the file to conflict on
|
48
|
+
change_file_and_commit('a', '')
|
49
|
+
|
50
|
+
# In the new branch, give it a new value
|
51
|
+
gitlib.checkout('fb', :new_branch => 'master') do
|
52
|
+
change_file_and_commit('a', 'hello')
|
53
|
+
end
|
54
|
+
|
55
|
+
# Change the value as well in the origional branch
|
56
|
+
gitlib.checkout('master') do
|
57
|
+
change_file_and_commit('a', 'goodbye')
|
58
|
+
end
|
59
|
+
|
60
|
+
# Merge in the new branch; don't error-out because will auto-fix.
|
61
|
+
gitlib.checkout('fb') do
|
62
|
+
gitlib.merge('master') rescue
|
63
|
+
change_file_and_commit('a', 'merged')
|
64
|
+
end
|
65
|
+
|
66
|
+
# Make another change on master
|
67
|
+
gitlib.checkout('master') do
|
68
|
+
change_file_and_commit('b', '')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Go back to the branch and try to rebase
|
72
|
+
gitlib.checkout('fb')
|
73
|
+
|
74
|
+
begin
|
75
|
+
gitprocess.rebase_to_master
|
76
|
+
raise "Should have raised RebaseError"
|
77
|
+
rescue Git::Process::RebaseError => exp
|
78
|
+
exp.resolved_files.should == ['a']
|
79
|
+
exp.unresolved_files.should == []
|
80
|
+
|
81
|
+
exp.commands.length.should == 3
|
82
|
+
exp.commands[0].should match /^# Verify/
|
83
|
+
exp.commands[1].should == 'git add a'
|
84
|
+
exp.commands[2].should == 'git rebase --continue'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe "remove current feature branch" do
|
92
|
+
|
93
|
+
def log_level
|
94
|
+
Logger::ERROR
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe "when handling the parking branch" do
|
99
|
+
|
100
|
+
it "should create it based on origin/master" do
|
101
|
+
gitlib.branch('fb', :base_branch => 'master')
|
102
|
+
clone('fb') do |gl|
|
103
|
+
gp = Git::Process.new(nil, gl)
|
104
|
+
gp.remove_feature_branch
|
105
|
+
gl.branches.current.name.should == '_parking_'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
it "should move it to the new origin/master if it already exists and is clean" do
|
111
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
112
|
+
gitlib.branch('_parking_', :base_branch => 'origin/master')
|
113
|
+
change_file_and_commit('a', '') # still on 'master'
|
114
|
+
|
115
|
+
gitlib.checkout('fb', :new_branch => 'origin/master')
|
116
|
+
|
117
|
+
gitprocess.remove_feature_branch
|
118
|
+
|
119
|
+
gitlib.branches.current.name.should == '_parking_'
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
it "should move it to the new origin/master if it already exists and changes are part of the current branch" do
|
124
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
125
|
+
|
126
|
+
gitlib.checkout('_parking_', :new_branch => 'origin/master') do
|
127
|
+
change_file_and_commit('a', '')
|
128
|
+
end
|
129
|
+
|
130
|
+
gitlib.branch('fb', :base_branch => '_parking_')
|
131
|
+
|
132
|
+
gitlib.checkout('origin/master') do
|
133
|
+
gitlib.merge('fb')
|
134
|
+
end
|
135
|
+
|
136
|
+
gitlib.checkout('fb')
|
137
|
+
|
138
|
+
gitprocess.remove_feature_branch
|
139
|
+
gitlib.branches.current.name.should == '_parking_'
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
it "should move it out of the way if it has unaccounted changes on it" do
|
144
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
145
|
+
gitlib.checkout('_parking_', :new_branch => 'origin/master')
|
146
|
+
change_file_and_commit('a', '')
|
147
|
+
gitlib.checkout('fb', :new_branch => 'origin/master')
|
148
|
+
|
149
|
+
gitlib.branches.include?('_parking_OLD_').should be_false
|
150
|
+
gitprocess.remove_feature_branch
|
151
|
+
gitlib.branches.include?('_parking_OLD_').should be_true
|
152
|
+
gitlib.branches.current.name.should == '_parking_'
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
it "should delete the old local branch when it has been merged into origin/master" do
|
159
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
160
|
+
change_file_and_commit('a', '') # still on 'master'
|
161
|
+
|
162
|
+
gitlib.checkout('fb', :new_branch => 'origin/master')
|
163
|
+
gitlib.branches.include?('fb').should be_true
|
164
|
+
gitprocess.remove_feature_branch
|
165
|
+
gitlib.branches.include?('fb').should be_false
|
166
|
+
gitlib.branches.current.name.should == '_parking_'
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
it "should raise an error when the local branch has not been merged into origin/master" do
|
171
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
172
|
+
gitlib.checkout('fb', :new_branch => 'origin/master')
|
173
|
+
change_file_and_commit('a', '') # on 'fb'
|
174
|
+
|
175
|
+
gitlib.branches.include?('fb').should be_true
|
176
|
+
expect {gitprocess.remove_feature_branch}.should raise_error Git::Process::GitProcessError
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
it "should delete the old remote branch" do
|
181
|
+
change_file_and_commit('a', '')
|
182
|
+
|
183
|
+
gitlib.branch('fb', :base_branch => 'master')
|
184
|
+
|
185
|
+
clone('fb') do |gl|
|
186
|
+
gl.branches.include?('origin/fb').should be_true
|
187
|
+
Git::Process.new(nil, gl).remove_feature_branch
|
188
|
+
gl.branches.include?('origin/fb').should be_false
|
189
|
+
gitlib.branches.include?('fb').should be_false
|
190
|
+
gl.branches.current.name.should == '_parking_'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
describe "when used while on _parking_" do
|
196
|
+
|
197
|
+
it 'should fail #rebase_to_master' do
|
198
|
+
gitlib.checkout('_parking_', :new_branch => 'master')
|
199
|
+
change_file_and_commit('a', '')
|
200
|
+
|
201
|
+
expect {gitprocess.rebase_to_master}.should raise_error Git::Process::ParkedChangesError
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
it 'should fail #sync_with_server' do
|
206
|
+
gitlib.checkout('_parking_', :new_branch => 'master')
|
207
|
+
change_file_and_commit('a', '')
|
208
|
+
|
209
|
+
expect {gitprocess.sync_with_server(false, false)}.should raise_error Git::Process::ParkedChangesError
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
describe "#new_feature_branch" do
|
218
|
+
|
219
|
+
def log_level
|
220
|
+
Logger::ERROR
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
it "should create the named branch against origin/master" do
|
225
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
226
|
+
|
227
|
+
new_branch = gitprocess.new_feature_branch('test_branch')
|
228
|
+
|
229
|
+
new_branch.name.should == 'test_branch'
|
230
|
+
new_branch.sha.should == gitlib.branches['origin/master'].sha
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
it "should bring committed changes on _parking_ over to the new branch" do
|
235
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
236
|
+
gitlib.checkout('_parking_', :new_branch => 'master')
|
237
|
+
change_file_and_commit('a', '')
|
238
|
+
change_file_and_commit('b', '')
|
239
|
+
|
240
|
+
new_branch = gitprocess.new_feature_branch('test_branch')
|
241
|
+
|
242
|
+
new_branch.name.should == 'test_branch'
|
243
|
+
Dir.chdir(gitlib.workdir) do |dir|
|
244
|
+
File.exists?('a').should be_true
|
245
|
+
File.exists?('b').should be_true
|
246
|
+
end
|
247
|
+
|
248
|
+
gitlib.branches.parking.should be_nil
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
it "should bring new/uncommitted changes on _parking_ over to the new branch" do
|
253
|
+
gitlib.branch('origin/master', :base_branch => 'master')
|
254
|
+
gitlib.checkout('_parking_', :new_branch => 'master')
|
255
|
+
change_file_and_commit('a', '')
|
256
|
+
change_file_and_add('b', '')
|
257
|
+
change_file('c', '')
|
258
|
+
|
259
|
+
new_branch = gitprocess.new_feature_branch('test_branch')
|
260
|
+
|
261
|
+
new_branch.name.should == 'test_branch'
|
262
|
+
Dir.chdir(gitlib.workdir) do |dir|
|
263
|
+
File.exists?('a').should be_true
|
264
|
+
File.exists?('b').should be_true
|
265
|
+
File.exists?('c').should be_true
|
266
|
+
end
|
267
|
+
|
268
|
+
gitlib.branches.parking.should be_nil
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
describe "#sync_with_server" do
|
275
|
+
|
276
|
+
def log_level
|
277
|
+
Logger::ERROR
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
it "should work when pushing with fast-forward" do
|
282
|
+
change_file_and_commit('a', '')
|
283
|
+
|
284
|
+
gitlib.branch('fb', :base_branch => 'master')
|
285
|
+
|
286
|
+
clone('fb') do |gl|
|
287
|
+
change_file_and_commit('a', 'hello', gl)
|
288
|
+
gl.branches.include?('origin/fb').should be_true
|
289
|
+
Git::Process.new(nil, gl).sync_with_server(false, false)
|
290
|
+
gl.branches.include?('origin/fb').should be_true
|
291
|
+
gitlib.branches.include?('fb').should be_true
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
it "should fail when pushing with non-fast-forward and no force" do
|
297
|
+
change_file_and_commit('a', '')
|
298
|
+
|
299
|
+
gitlib.branch('fb', :base_branch => 'master')
|
300
|
+
|
301
|
+
clone('fb') do |gl|
|
302
|
+
gitlib.checkout('fb') do
|
303
|
+
change_file_and_commit('a', 'hello', gitlib)
|
304
|
+
end
|
305
|
+
|
306
|
+
expect {Git::Process.new(nil, gl).sync_with_server(false, false)}.should raise_error Git::GitExecuteError
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
it "should work when pushing with non-fast-forward and force" do
|
312
|
+
change_file_and_commit('a', '')
|
313
|
+
|
314
|
+
gitlib.branch('fb', :base_branch => 'master')
|
315
|
+
|
316
|
+
clone('fb') do |gl|
|
317
|
+
gitlib.checkout('fb') do
|
318
|
+
change_file_and_commit('a', 'hello', gitlib)
|
319
|
+
end
|
320
|
+
|
321
|
+
# expect {Git::Process.new(nil, gl).sync_with_server(false, true)}.should_not raise_error Git::GitExecuteError
|
322
|
+
Git::Process.new(nil, gl).sync_with_server(false, true)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|