nkryptic-gitstart 0.1.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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/bin/gitstart +6 -0
- data/lib/gitstart.rb +250 -0
- data/spec/gitstart_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +84 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 nkryptic
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= gitstart
|
2
|
+
|
3
|
+
Based upon http://github.com/gma/git-me-up
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 nkryptic. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gemspec|
|
7
|
+
gemspec.name = "gitstart"
|
8
|
+
gemspec.summary = "Initialize a git-svn clone of a repository including svn:externals"
|
9
|
+
gemspec.description = "Initialize a git-svn clone of a repository including svn:externals"
|
10
|
+
gemspec.email = "nkryptic@gmail.com"
|
11
|
+
gemspec.homepage = "http://github.com/nkryptic/gitstart"
|
12
|
+
gemspec.authors = ["nkryptic"]
|
13
|
+
gemspec.add_development_dependency "rspec"
|
14
|
+
gemspec.add_development_dependency "yard"
|
15
|
+
# gemspec is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'reek/rake_task'
|
38
|
+
Reek::RakeTask.new do |t|
|
39
|
+
t.fail_on_error = true
|
40
|
+
t.verbose = false
|
41
|
+
t.source_files = 'lib/**/*.rb'
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
task :reek do
|
45
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
require 'roodi'
|
51
|
+
require 'roodi_task'
|
52
|
+
RoodiTask.new do |t|
|
53
|
+
t.verbose = false
|
54
|
+
end
|
55
|
+
rescue LoadError
|
56
|
+
task :roodi do
|
57
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
task :default => :spec
|
62
|
+
|
63
|
+
begin
|
64
|
+
require 'yard'
|
65
|
+
YARD::Rake::YardocTask.new
|
66
|
+
rescue LoadError
|
67
|
+
task :yardoc do
|
68
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
69
|
+
end
|
70
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/gitstart
ADDED
data/lib/gitstart.rb
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Gitstart
|
4
|
+
|
5
|
+
def self.ui
|
6
|
+
@ui ||= ::Gitstart::UI.new(STDOUT)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.ui=(io)
|
10
|
+
@ui = ::Gitstart::UI.new(io)
|
11
|
+
end
|
12
|
+
|
13
|
+
class UI
|
14
|
+
def initialize(io = nil, verbose = false)
|
15
|
+
@io = io
|
16
|
+
@verbose = verbose
|
17
|
+
@indent_string = "\t"
|
18
|
+
@indent_level = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def indent
|
22
|
+
@indent_level += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def unindent
|
26
|
+
if @indent_level > 0
|
27
|
+
@indent_level -= 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def puts(*args)
|
32
|
+
return unless @io
|
33
|
+
|
34
|
+
if args.empty?
|
35
|
+
@io.puts ""
|
36
|
+
else
|
37
|
+
args.each { |msg| @io.puts("#{@indent_string * @indent_level}#{msg}") }
|
38
|
+
end
|
39
|
+
|
40
|
+
@io.flush
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def abort(msg)
|
45
|
+
@io && Kernel.abort("gitstart: #{msg}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def vputs(*args)
|
49
|
+
puts(*args) if @verbose
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Help
|
54
|
+
# def show_help(command, commands = commands)
|
55
|
+
# subcommand = command.to_s.empty? ? nil : "#{command} "
|
56
|
+
# ui.puts "Usage: rip #{subcommand}COMMAND [options]", ""
|
57
|
+
# ui.puts "Commands available:"
|
58
|
+
#
|
59
|
+
# show_command_table begin
|
60
|
+
# commands.zip begin
|
61
|
+
# commands.map { |c| @help[c].first unless @help[c].nil? }
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
|
66
|
+
private
|
67
|
+
def ui
|
68
|
+
::Gitstart.ui
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
module Sh
|
73
|
+
module Svn
|
74
|
+
extend self
|
75
|
+
|
76
|
+
def get_externals(repo, recursive=true)
|
77
|
+
args = ''
|
78
|
+
if recursive
|
79
|
+
args << '-R'
|
80
|
+
end
|
81
|
+
|
82
|
+
`svn propget svn:externals #{args} #{repo}`
|
83
|
+
end
|
84
|
+
|
85
|
+
def log(repo, limit=nil)
|
86
|
+
args = ''
|
87
|
+
if limit
|
88
|
+
args << "--limit #{limit}"
|
89
|
+
end
|
90
|
+
`svn log #{args} #{repo}`
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module Git
|
95
|
+
extend self
|
96
|
+
|
97
|
+
def checkout(branch_name)
|
98
|
+
`git checkout -b #{branch_name} 2>/dev/null`
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module GitSvn
|
103
|
+
extend self
|
104
|
+
|
105
|
+
def clone(repo, target, revision=nil)
|
106
|
+
args = ''
|
107
|
+
if revision
|
108
|
+
args << "-r #{revision}"
|
109
|
+
end
|
110
|
+
|
111
|
+
`git svn clone #{args} #{repo} #{target} 2>&1`
|
112
|
+
end
|
113
|
+
|
114
|
+
def show_ignore
|
115
|
+
`git svn show-ignore`
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
module Application
|
121
|
+
extend self
|
122
|
+
extend Help
|
123
|
+
|
124
|
+
BRANCH = "working"
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
def run(args)
|
129
|
+
unless args.size == 2
|
130
|
+
ui.puts "Usage: gitstart <svn-repository> <target-dir>"
|
131
|
+
exit 1
|
132
|
+
end
|
133
|
+
|
134
|
+
repo, target = args
|
135
|
+
fullpath = File.expand_path(target)
|
136
|
+
|
137
|
+
check_for_local_dir(fullpath)
|
138
|
+
clone_repository(repo, fullpath)
|
139
|
+
clone_externals(repo, fullpath)
|
140
|
+
create_working_branch(fullpath)
|
141
|
+
end
|
142
|
+
|
143
|
+
def check_for_local_dir(target)
|
144
|
+
if File.exist?(target)
|
145
|
+
ui.puts "Error: target #{target} already exists - please move it!"
|
146
|
+
exit 1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def clone_repository(repo, target)
|
151
|
+
ui.puts "finding latest revision of #{repo}"
|
152
|
+
revision = get_latest_revision(repo)
|
153
|
+
|
154
|
+
ui.puts "creating git repository in #{target}"
|
155
|
+
ui.indent
|
156
|
+
|
157
|
+
results = Sh::GitSvn.clone(repo, target, revision)
|
158
|
+
empty_dirs = results.split("\n").collect {|line| line =~ /^W: \+empty_dir: (.*)$/; $1}.compact
|
159
|
+
empty_dirs.each do |dir|
|
160
|
+
ui.puts "making empty directory: #{dir}"
|
161
|
+
FileUtils.mkdir_p( File.join(target, dir) )
|
162
|
+
end
|
163
|
+
|
164
|
+
Dir.chdir(target) do
|
165
|
+
ignore_generated_files
|
166
|
+
end
|
167
|
+
|
168
|
+
ui.unindent
|
169
|
+
end
|
170
|
+
|
171
|
+
def parse_external_repos(repos_str)
|
172
|
+
results = repos_str.chomp.split("\n").reject{|line| line.nil? or line.empty?}
|
173
|
+
|
174
|
+
repos = results.collect do |line|
|
175
|
+
line.split(' ', 2)
|
176
|
+
end
|
177
|
+
|
178
|
+
repos
|
179
|
+
end
|
180
|
+
|
181
|
+
def get_externals(repo)
|
182
|
+
results = Sh::Svn.get_externals(repo)
|
183
|
+
results = results.chomp.split("\n\n").reject{|line| line.nil? or line.empty?}
|
184
|
+
|
185
|
+
externals = results.collect do |line|
|
186
|
+
dir, repos = line.split(' - ', 2)
|
187
|
+
dir = File.basename(dir.gsub(repo, ''))
|
188
|
+
repos = parse_external_repos(repos)
|
189
|
+
[dir, repos]
|
190
|
+
end
|
191
|
+
|
192
|
+
externals
|
193
|
+
end
|
194
|
+
|
195
|
+
def clone_externals(repo, target)
|
196
|
+
ui.puts "checking for svn:externals to install from #{repo}"
|
197
|
+
ui.indent
|
198
|
+
|
199
|
+
externals = get_externals(repo)
|
200
|
+
|
201
|
+
Dir.chdir(target) do
|
202
|
+
externals_dir=".externals"
|
203
|
+
FileUtils.mkdir_p(externals_dir)
|
204
|
+
|
205
|
+
File.open('.git/info/exclude', 'a') { |f| f.puts externals_dir }
|
206
|
+
|
207
|
+
externals.each do |dir, repos|
|
208
|
+
repos.each do |ext_dir, ext_repo|
|
209
|
+
unless File.exist?(File.join(externals_dir, ext_dir))
|
210
|
+
clone_repository(ext_repo, File.join(externals_dir, ext_dir))
|
211
|
+
end
|
212
|
+
|
213
|
+
ui.puts "symlinking #{ext_dir} into #{target}/#{dir}"
|
214
|
+
Dir.chdir(dir) do
|
215
|
+
FileUtils.symlink(File.join(target, externals_dir, ext_dir), ext_dir, :force => true)
|
216
|
+
end
|
217
|
+
File.open('.git/info/exclude', 'a') { |f| f.puts File.join(dir, ext_dir) }
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
ui.unindent
|
223
|
+
end
|
224
|
+
|
225
|
+
def create_working_branch(target)
|
226
|
+
ui.puts "creating '#{BRANCH}' branch on #{target}"
|
227
|
+
Dir.chdir( target ) do
|
228
|
+
result = Sh::Git.checkout(BRANCH)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def get_latest_revision(repo)
|
233
|
+
results = Sh::Svn.log(repo, 1).chomp.split("\n")
|
234
|
+
rev = results[1].split()[0].gsub(/^r/, '')
|
235
|
+
rev
|
236
|
+
end
|
237
|
+
|
238
|
+
def ignore_generated_files
|
239
|
+
ui.puts "setting ignored files from subversion (this can take a while)"
|
240
|
+
|
241
|
+
File.open('.git/info/exclude', 'a') do |f|
|
242
|
+
f.puts Sh::GitSvn.show_ignore
|
243
|
+
f.puts
|
244
|
+
f.puts "# Git files"
|
245
|
+
f.puts ".gitignore"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nkryptic-gitstart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nkryptic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-12 00:00:00 -07:00
|
13
|
+
default_executable: gitstart
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Initialize a git-svn clone of a repository including svn:externals
|
36
|
+
email: nkryptic@gmail.com
|
37
|
+
executables:
|
38
|
+
- gitstart
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/gitstart
|
52
|
+
- lib/gitstart.rb
|
53
|
+
- spec/gitstart_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/nkryptic/gitstart
|
57
|
+
licenses:
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: Initialize a git-svn clone of a repository including svn:externals
|
82
|
+
test_files:
|
83
|
+
- spec/gitstart_spec.rb
|
84
|
+
- spec/spec_helper.rb
|