-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit_manager_spec.rb
More file actions
153 lines (113 loc) · 6.49 KB
/
git_manager_spec.rb
File metadata and controls
153 lines (113 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require 'spec_helper.rb'
require 'git'
describe GITRepoManager do
LOCAL_REPOS = File.join(Dir.pwd, 'spec/files/test_repos')
TEST_CONFIG = 'spec/files/config/repos.yml'
# TODO move
TEST_REPO_USING_SUBMODULE = "file:///tmp/spec_testing/using_submodule.git"
TEST_REPO_SUBMODULE = "file:///tmp/spec_testing/submodule.git"
before(:all) do
initalize_repos
end
after(:all) do
remove_temp_directory
end
context 'when created' do
it 'should raise an error if config file was not found' do
lambda { GITRepoManager.new('config/non_existing_repos.yml') }.should raise_error()
end
end
context 'when created with a specfic config file' do
manager = GITRepoManager.new(TEST_CONFIG, LOCAL_REPOS)
it 'should load the configuration file and create a repositories directory' do
manager.config_file.should == TEST_CONFIG
File.exists?(manager.clone_path).should be_true
end
it 'should give a list of active submodules' do
manager.submodules.should == [:submodule]
end
it 'should give access to config data' do
manager.config_hash.should == {
:using_submodule => {:uri => TEST_REPO_USING_SUBMODULE},
:submodule => {:submoduled_in => [:using_submodule],
:uri => TEST_REPO_SUBMODULE,
:sync_only_branches => [:testing, :master]}
}
end
context 'and is receiving submodule updates' do
after(:all) do
FileUtils.rm_r(LOCAL_REPOS) if File.exists?(LOCAL_REPOS)
end
it 'should clone projects that are using submodules' do
# Call update with irreleveant data, and make sure stuff is cloned
manager.update_submodule('some_model', 'master', 'x')
File.exists?(File.join(manager.clone_path, 'using_submodule', '.git')).should be_true
File.exists?(File.join(manager.clone_path, 'submodules')).should be_false
local_repo_clone = local_using_submodule_checkout
local_repo_clone.pull
local_using_submodule_checkout.log.size.should == 2 # First and the submodule commit.
end
it 'should pull from projects already cloned so that it has the lastest commits locally' do
change_using_submodule_via_third_party_checkout
File.exists?(File.join(manager.clone_path, 'using_submodule', '.git')).should be_true
manager.update_submodule('some_model', 'master', 'x')
local_repo_clone = local_using_submodule_checkout
local_repo_clone.log.size.should == 3 # First and the submodule commit.
local_repo_clone.log.first.message.should == 'New line in using submodule readme.'
end
it 'should auto commit an update to repositories using submodules' do
commit = change_submodule_via_third_party_checkout
local_using_submodule_checkout.log.first.message.should_not == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
manager.update_submodule(TEST_REPO_SUBMODULE, 'master', commit.sha)
local_using_submodule_checkout.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
GITRepoManager.git_commit_author_name(local_using_submodule_checkout.log.first).should == "Third party <thirdparty@localhost.local>"
end
it 'should push auto commits to the remote repository' do
commit = change_submodule_via_third_party_checkout
manager.update_submodule(TEST_REPO_SUBMODULE, 'master', commit.sha)
third_party_using_submodule_checkout.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should work with http://github.com prefixes' do
commit = change_submodule_via_third_party_checkout
manager.update_submodule('http://github.com/tmp/spec_testing/submodule', 'master', commit.sha)
local_using_submodule_checkout.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should work with git@github.com: prefixes' do
commit = change_submodule_via_third_party_checkout
manager.update_submodule('git@github.com:tmp/spec_testing/submodule', 'master', commit.sha)
local_repo_clone = local_using_submodule_checkout
local_repo_clone.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should not do anything for different branches' do
commit = change_submodule_via_third_party_checkout
manager.update_submodule(TEST_REPO_SUBMODULE, 'stuff', commit.sha)
local_using_submodule_checkout.log.first.message.should_not == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should create local copies of branches that exist remotely when they match the submodules branches' do
commit = change_submodule_via_third_party_checkout('testing')
change_using_submodule_via_third_party_checkout('testing')
manager.update_submodule(TEST_REPO_SUBMODULE, 'testing', commit.sha)
local_repo_clone = local_using_submodule_checkout
local_repo_clone.checkout('testing')
local_repo_clone.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should not create local copies of branches that exist remotely when they are not on the sync only list' do
commit = change_submodule_via_third_party_checkout('unstable')
change_using_submodule_via_third_party_checkout('unstable')
manager.update_submodule(TEST_REPO_SUBMODULE, 'unstable', commit.sha)
local_repo_clone = local_using_submodule_checkout
local_repo_clone.checkout('unstable')
local_repo_clone.log.first.message.should_not == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
it 'should create local copies of branches that exist remotely when they match the submodule branches and there is no sync list' do
commit = change_submodule_via_third_party_checkout('unstable')
change_using_submodule_via_third_party_checkout('unstable')
manager.ignore_sync_only_branch_list = true
manager.update_submodule(TEST_REPO_SUBMODULE, 'unstable', commit.sha)
local_repo_clone = local_using_submodule_checkout
local_repo_clone.checkout('unstable')
local_repo_clone.log.first.message.should == "Auto-updating submodule to commit spec_testing/submodule@#{commit.sha}."
end
end
end
end