hubbard 0.0.6 → 0.0.7
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/.gitignore +1 -1
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/bin/hubbard +30 -19
- data/commands/create-project.rb +1 -1
- data/commands/git-receive-pack.rb +1 -1
- data/commands/git-upload-pack.rb +1 -1
- data/commands/list-forks.rb +1 -1
- data/commands/list-keys.rb +8 -1
- data/commands/list-projects.rb +9 -2
- data/commands/list-repositories.rb +9 -2
- data/commands/list-users.rb +9 -2
- data/lib/hubbard.rb +10 -0
- data/spec/hubbard_spec.rb +2 -37
- data/spec/spec_helper.rb +39 -1
- data/spec/yaml_spec.rb +28 -0
- metadata +5 -4
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -11,10 +11,9 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/mfoemmel/hubbard"
|
12
12
|
gem.authors = ["Matthew Foemmel"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.files << Dir['commands/*.rb']
|
14
|
+
gem.files << Dir['commands/*.rb'] + Dir['lib/**/*.rb']
|
15
15
|
gem.bindir = 'bin'
|
16
16
|
gem.executables << 'hubbard'
|
17
|
-
gem.require_path = ''
|
18
17
|
end
|
19
18
|
Jeweler::GemcutterTasks.new
|
20
19
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/bin/hubbard
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require 'fileutils'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
7
|
+
require 'hubbard'
|
8
|
+
|
9
|
+
defaults = { :format => :text }
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
formats = [:text, :yaml]
|
13
|
+
opts.on("--private", "Create project with visibility set to private") do |o|
|
14
|
+
options[:private] = o
|
15
|
+
end
|
16
|
+
opts.on("-f", "--format [FORMAT]", formats,
|
17
|
+
"Select format (#{formats.join(', ')})") do |o|
|
18
|
+
options[:format] = o
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
OPTIONS = defaults.merge(options)
|
22
|
+
OPTIONS.freeze
|
12
23
|
|
13
|
-
FileUtils.mkdir_p(File.join(HUB_DATA, "projects"))
|
14
|
-
FileUtils.mkdir_p(File.join(HUB_DATA, "accounts"))
|
24
|
+
FileUtils.mkdir_p(File.join(Hubbard::HUB_DATA, "projects"))
|
25
|
+
FileUtils.mkdir_p(File.join(Hubbard::HUB_DATA, "accounts"))
|
15
26
|
|
16
27
|
def next_arg(msg)
|
17
28
|
if ARGV.length < 1
|
@@ -29,21 +40,21 @@ def check_status(msg)
|
|
29
40
|
end
|
30
41
|
|
31
42
|
def validate_project_name(name)
|
32
|
-
if name !~ /#{PROJECT_REGEX}/
|
43
|
+
if name !~ /#{Hubbard::PROJECT_REGEX}/
|
33
44
|
$stderr.put "Project names can only contain letter, numbers, and hyphens"
|
34
45
|
exit 1
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
49
|
def validate_repository_name(name)
|
39
|
-
if name !~ /#{REPOSITORY_REGEX}/
|
50
|
+
if name !~ /#{Hubbard::REPOSITORY_REGEX}/
|
40
51
|
$stderr.put "Repository names can only contain letter, numbers, and hyphens"
|
41
52
|
exit 1
|
42
53
|
end
|
43
54
|
end
|
44
55
|
|
45
56
|
def validate_user_name(name)
|
46
|
-
if name !~ /#{USERNAME_REGEX}/
|
57
|
+
if name !~ /#{Hubbard::USERNAME_REGEX}/
|
47
58
|
$stderr.put "User names can only contain letter, numbers, and hyphens"
|
48
59
|
exit 1
|
49
60
|
end
|
@@ -116,11 +127,11 @@ def is_authorized(project_name, action)
|
|
116
127
|
end
|
117
128
|
|
118
129
|
def find_account_dir(user_name)
|
119
|
-
File.join(HUB_DATA, "accounts", user_name)
|
130
|
+
File.join(Hubbard::HUB_DATA, "accounts", user_name)
|
120
131
|
end
|
121
132
|
|
122
133
|
def find_project_dir(project_name)
|
123
|
-
File.join(HUB_DATA, "projects", project_name)
|
134
|
+
File.join(Hubbard::HUB_DATA, "projects", project_name)
|
124
135
|
end
|
125
136
|
|
126
137
|
def find_repository_dir(project_name, repository_dir)
|
@@ -147,13 +158,13 @@ end
|
|
147
158
|
|
148
159
|
def sync_keys
|
149
160
|
File.open(File.expand_path("~/.ssh/authorized_keys"), "w") do |file|
|
150
|
-
Dir.entries(File.join(HUB_DATA, "accounts")).each do |account|
|
161
|
+
Dir.entries(File.join(Hubbard::HUB_DATA, "accounts")).each do |account|
|
151
162
|
next if account == '.' || account == '..'
|
152
|
-
key_dir = File.join(HUB_DATA, "accounts", account, "keys")
|
163
|
+
key_dir = File.join(Hubbard::HUB_DATA, "accounts", account, "keys")
|
153
164
|
Dir.entries(key_dir).each do |name|
|
154
165
|
next if name == '.' || name == '..'
|
155
166
|
key = File.read(File.join(key_dir, name))
|
156
|
-
file <<
|
167
|
+
file << %Q~command="hubbard #{account}",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty #{key} #{name}\n~
|
157
168
|
end
|
158
169
|
end
|
159
170
|
end
|
data/commands/create-project.rb
CHANGED
@@ -9,6 +9,6 @@ end
|
|
9
9
|
unless Dir.mkdir(dir)
|
10
10
|
$stderr.puts "Unable to create directory: #{dir}"
|
11
11
|
end
|
12
|
-
visibility =
|
12
|
+
visibility = OPTIONS[:private] ? "private" : "public"
|
13
13
|
File.open(File.join(dir, ".permissions"), "w") { |f| f << "#{@username}=admin\n" }
|
14
14
|
File.open(File.join(dir, ".visibility"), "w") { |f| f << "#{visibility}\n" }
|
data/commands/git-upload-pack.rb
CHANGED
data/commands/list-forks.rb
CHANGED
@@ -3,7 +3,7 @@ repository_name = read_repository_name
|
|
3
3
|
authorize(project_name, 'read')
|
4
4
|
forkid = Dir.chdir(find_repository_dir(project_name, repository_name)) { `git config --get hubbard.forkid` }
|
5
5
|
project_dir = find_project_dir(project_name)
|
6
|
-
Dir.foreach(File.join(HUB_DATA, 'projects')) do |dir|
|
6
|
+
Dir.foreach(File.join(Hubbard::HUB_DATA, 'projects')) do |dir|
|
7
7
|
next if dir == "." || dir == ".."
|
8
8
|
next unless is_authorized(dir, 'read')
|
9
9
|
Dir.foreach(find_project_dir(project_name)) do |repository_name|
|
data/commands/list-keys.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
keys = []
|
1
2
|
dirname = File.join(find_account_dir(@username), "keys")
|
2
3
|
Dir.entries(dirname).each do |name|
|
3
4
|
next if name == '.' || name == '..'
|
4
|
-
|
5
|
+
keys << name
|
6
|
+
end
|
7
|
+
|
8
|
+
if OPTIONS[:format] == :yaml
|
9
|
+
puts YAML::dump(keys)
|
10
|
+
else
|
11
|
+
keys.each { |k| puts k }
|
5
12
|
end
|
data/commands/list-projects.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
|
1
|
+
projects = []
|
2
|
+
Dir.foreach(File.join(Hubbard::HUB_DATA, 'projects')) do |dir|
|
2
3
|
next if dir == "." || dir == ".."
|
3
4
|
if is_authorized(dir, 'read')
|
4
|
-
|
5
|
+
projects << dir
|
5
6
|
end
|
6
7
|
end
|
8
|
+
|
9
|
+
if OPTIONS[:format] == :yaml
|
10
|
+
puts YAML::dump(projects)
|
11
|
+
else
|
12
|
+
projects.each { |p| puts p }
|
13
|
+
end
|
@@ -1,7 +1,14 @@
|
|
1
1
|
project_name = read_project_name
|
2
2
|
authorize(project_name, 'read')
|
3
|
+
repositories = []
|
3
4
|
Dir.foreach(find_project_dir(project_name)) do |repository_name|
|
4
5
|
next if repository_name =~ /^\./
|
5
|
-
git_url = "#{ENV['USER']}@#{HUB_HOST}:#{project_name}/#{repository_name}.git"
|
6
|
-
|
6
|
+
git_url = "#{ENV['USER']}@#{Hubbard::HUB_HOST}:#{project_name}/#{repository_name}.git"
|
7
|
+
repositories << { :name => repository_name, :url => git_url }
|
8
|
+
end
|
9
|
+
|
10
|
+
if OPTIONS[:format] == :yaml
|
11
|
+
puts YAML::dump(repositories)
|
12
|
+
else
|
13
|
+
repositories.each { |r| puts "#{r[:name]}\t#{r[:url]}" }
|
7
14
|
end
|
data/commands/list-users.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
users = []
|
2
|
+
Dir.entries(File.join(Hubbard::HUB_DATA, "accounts")).each do |entry|
|
2
3
|
next if entry == '.' || entry == '..'
|
3
|
-
|
4
|
+
users << entry
|
5
|
+
end
|
6
|
+
|
7
|
+
if OPTIONS[:format] == :yaml
|
8
|
+
puts YAML::dump(users)
|
9
|
+
else
|
10
|
+
users.each { |u| puts u }
|
4
11
|
end
|
data/lib/hubbard.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Hubbard
|
4
|
+
PROJECT_REGEX='[a-zA-Z0-9\-]{1,32}'
|
5
|
+
REPOSITORY_REGEX='[a-zA-Z0-9\-]{1,32}'
|
6
|
+
USERNAME_REGEX='[a-zA-Z0-9\-]{1,32}'
|
7
|
+
|
8
|
+
HUB_DATA = ENV['HUB_DATA'] || File.expand_path("~/.hubbard")
|
9
|
+
HUB_HOST = ENV['HUB_HOST'] || Socket.gethostname
|
10
|
+
end
|
data/spec/hubbard_spec.rb
CHANGED
@@ -1,44 +1,9 @@
|
|
1
|
-
|
2
|
-
# a bunch of GIT_* environment variables,
|
3
|
-
# which mess everything up, so undo.
|
4
|
-
ENV.each do |key,value|
|
5
|
-
ENV[key] = nil if key =~ /^GIT_/
|
6
|
-
end
|
7
|
-
|
8
|
-
HUB=File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "hubbard"))
|
9
|
-
|
1
|
+
require 'spec_helper'
|
10
2
|
require 'fileutils'
|
11
3
|
|
12
|
-
ENV['HUB_USER'] = HUB_USER = "hub"
|
13
|
-
ENV['HUB_HOST'] = HUB_HOST = "example.com"
|
14
|
-
ENV['HUB_DATA'] = HUB_DATA = File.expand_path(File.join(File.dirname(__FILE__), '..', "data"))
|
15
|
-
ENV['GIT_SSH'] = File.expand_path(File.join(File.dirname(__FILE__), "gitssh"))
|
16
|
-
|
17
|
-
def hub(username, command, input=nil)
|
18
|
-
if input
|
19
|
-
result = `echo #{input} | #{HUB} #{username} #{command}`
|
20
|
-
else
|
21
|
-
result = `#{HUB} #{username} #{command}`
|
22
|
-
end
|
23
|
-
if $?.exitstatus != 0
|
24
|
-
raise "Command failed: hub #{username} #{command}\n#{result}"
|
25
|
-
end
|
26
|
-
result
|
27
|
-
end
|
28
|
-
|
29
|
-
def git(username, command)
|
30
|
-
ENV['HUB_USERNAME'] = username
|
31
|
-
result = `git #{command}`
|
32
|
-
if $?.exitstatus != 0
|
33
|
-
raise "Command failed: git #{command}:\n#{result}"
|
34
|
-
end
|
35
|
-
result
|
36
|
-
end
|
37
|
-
|
38
4
|
describe "Hubble" do
|
39
5
|
before(:each) do
|
40
|
-
|
41
|
-
FileUtils.rm_rf "tmp"
|
6
|
+
reset_file_system
|
42
7
|
end
|
43
8
|
|
44
9
|
it "should create project" do
|
data/spec/spec_helper.rb
CHANGED
@@ -5,5 +5,43 @@ require 'spec'
|
|
5
5
|
require 'spec/autorun'
|
6
6
|
|
7
7
|
Spec::Runner.configure do |config|
|
8
|
-
|
8
|
+
end
|
9
|
+
|
10
|
+
# Something in the Rakefile is generating
|
11
|
+
# a bunch of GIT_* environment variables,
|
12
|
+
# which mess everything up, so undo.
|
13
|
+
ENV.each do |key,value|
|
14
|
+
ENV[key] = nil if key =~ /^GIT_/
|
15
|
+
end
|
16
|
+
|
17
|
+
HUB=File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "hubbard"))
|
18
|
+
ENV['HUB_USER'] = HUB_USER = "hub"
|
19
|
+
ENV['HUB_HOST'] = HUB_HOST = "example.com"
|
20
|
+
ENV['HUB_DATA'] = HUB_DATA = File.expand_path(File.join(File.dirname(__FILE__), '..', "data"))
|
21
|
+
ENV['GIT_SSH'] = File.expand_path(File.join(File.dirname(__FILE__), "gitssh"))
|
22
|
+
|
23
|
+
def hub(username, command, input=nil)
|
24
|
+
if input
|
25
|
+
result = `echo #{input} | #{HUB} #{username} #{command}`
|
26
|
+
else
|
27
|
+
result = `#{HUB} #{username} #{command}`
|
28
|
+
end
|
29
|
+
if $?.exitstatus != 0
|
30
|
+
raise "Command failed: hub #{username} #{command}\n#{result}"
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def git(username, command)
|
36
|
+
ENV['HUB_USERNAME'] = username
|
37
|
+
result = `git #{command}`
|
38
|
+
if $?.exitstatus != 0
|
39
|
+
raise "Command failed: git #{command}:\n#{result}"
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset_file_system
|
45
|
+
FileUtils.rm_rf HUB_DATA
|
46
|
+
FileUtils.rm_rf "tmp"
|
9
47
|
end
|
data/spec/yaml_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
YAML_OPTION=" -f yaml "
|
5
|
+
describe "Hubble with yaml output" do
|
6
|
+
before(:each) do
|
7
|
+
reset_file_system
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should load list-projects" do
|
11
|
+
hub("yammer", "create-project a")
|
12
|
+
hub("yammer", "create-project b")
|
13
|
+
hub("yammer", "create-project c")
|
14
|
+
|
15
|
+
projects = YAML::load(hub("#{YAML_OPTION} yammer", "list-projects"))
|
16
|
+
projects.should == ["a", "b", "c"]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create repositories" do
|
20
|
+
hub("yammer", "create-project a")
|
21
|
+
hub("yammer", "create-repository a b")
|
22
|
+
|
23
|
+
repositories = YAML::load(hub("yammer", "#{YAML_OPTION} list-repositories a"))
|
24
|
+
repositories.length.should == 1
|
25
|
+
repositories.first[:name].should == "b"
|
26
|
+
repositories.first[:url].should == "#{ENV['USER']}@#{HUB_HOST}:a/b.git"
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubbard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Foemmel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-29 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +26,6 @@ description: Hubbard is a command line tool for managing git repositories.
|
|
26
26
|
email: git@foemmel.com
|
27
27
|
executables:
|
28
28
|
- hubbard
|
29
|
-
- hubbard~
|
30
29
|
- hubbard
|
31
30
|
extensions: []
|
32
31
|
|
@@ -63,6 +62,7 @@ files:
|
|
63
62
|
- spec/hubbard_spec.rb
|
64
63
|
- spec/spec.opts
|
65
64
|
- spec/spec_helper.rb
|
65
|
+
- spec/yaml_spec.rb
|
66
66
|
has_rdoc: true
|
67
67
|
homepage: http://github.com/mfoemmel/hubbard
|
68
68
|
licenses: []
|
@@ -71,7 +71,7 @@ post_install_message:
|
|
71
71
|
rdoc_options:
|
72
72
|
- --charset=UTF-8
|
73
73
|
require_paths:
|
74
|
-
-
|
74
|
+
- lib
|
75
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
@@ -92,5 +92,6 @@ signing_key:
|
|
92
92
|
specification_version: 3
|
93
93
|
summary: Hubbard is a command line tool for managing git repositories.
|
94
94
|
test_files:
|
95
|
+
- spec/yaml_spec.rb
|
95
96
|
- spec/hubbard_spec.rb
|
96
97
|
- spec/spec_helper.rb
|