git-projects 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git-projects/version.rb +1 -1
- data/lib/git-projects.rb +5 -7
- data/lib/helpers/git_project.rb +71 -62
- data/lib/helpers/project.rb +6 -6
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 145601748d4cda601bc403ea515b76512ab3230f
|
4
|
+
data.tar.gz: 14f0a8efee0d133ff9e286a3358c47dbe7cb3a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 138dd6c41ae38666eae2efd1ddd3e746183d6dc42961243e3d1b4eda5c1bb7069d7abf7bf6f2733e3b71bd8693455f143d954dec573bcb84e64212709e1d2f8c
|
7
|
+
data.tar.gz: af62eb78ea5f794107b87cdfada3718a373bdc621b451c33b838ab25fbdbf8668bea6879d6aa55054b549ffddb039e537a07a9057a0dc4c32e4686e15c5d0a1d
|
data/lib/git-projects/version.rb
CHANGED
data/lib/git-projects.rb
CHANGED
@@ -11,20 +11,18 @@ program_desc 'Easily manage Git projects'
|
|
11
11
|
|
12
12
|
desc 'Create a config'
|
13
13
|
command :config do |c|
|
14
|
-
c.action do |global_options,options,args|
|
14
|
+
c.action do |global_options, options, args|
|
15
15
|
config_path = "#{args[0]}/git-projects.yml"
|
16
16
|
group = args[1] || nil
|
17
17
|
GitProject.create_config(args[0], group)
|
18
|
-
if File.open(config_path)
|
19
|
-
puts "Successfully created git-projects.yml".green
|
20
|
-
end
|
18
|
+
puts 'Created git-projects.yml'.green if File.open(config_path)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
desc 'Clone or initialize all projects'
|
25
23
|
command :init do |c|
|
26
24
|
c.action do
|
27
|
-
GitProject.check_config
|
25
|
+
GitProject.check_config
|
28
26
|
GitProject.new(ENV['GIT_PROJECTS']).init
|
29
27
|
end
|
30
28
|
end
|
@@ -39,10 +37,10 @@ end
|
|
39
37
|
|
40
38
|
desc 'Fetch changes from all remotes'
|
41
39
|
command :fetch do |c|
|
42
|
-
c.action do |global_options,options,args|
|
40
|
+
c.action do |global_options, options, args|
|
43
41
|
GitProject.check_config
|
44
42
|
if GitProject.new(ENV['GIT_PROJECTS']).fetch_all(args[0])
|
45
|
-
puts
|
43
|
+
puts 'Successfully fetched changes'.green
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
data/lib/helpers/git_project.rb
CHANGED
@@ -3,25 +3,24 @@ require 'git'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'colorize'
|
5
5
|
|
6
|
+
# GitProject contains helpers for Git commands
|
6
7
|
class GitProject
|
7
|
-
|
8
|
-
attr :project
|
8
|
+
attr_reader :project
|
9
9
|
|
10
10
|
def initialize(config)
|
11
11
|
@project = Project.new(config)
|
12
12
|
end
|
13
13
|
|
14
14
|
class << self
|
15
|
-
|
16
15
|
# Create YAML file
|
17
16
|
def create_yaml_file(config_file, projects)
|
18
|
-
File.open(config_file,
|
19
|
-
f.write projects.to_yaml.gsub(/- /,'').gsub(/ /,' ').gsub(/---/,'')
|
17
|
+
File.open(config_file, 'w') do |f|
|
18
|
+
f.write projects.to_yaml.gsub(/- /, '').gsub(/ /, ' ').gsub(/---/, '')
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
# Create a hash for remotes
|
24
|
-
def add_remotes_to_hash(g,
|
23
|
+
def add_remotes_to_hash(g, dir)
|
25
24
|
remotes_h = {}
|
26
25
|
r = {}
|
27
26
|
remotes_h.tap do |remotes|
|
@@ -35,37 +34,34 @@ class GitProject
|
|
35
34
|
end
|
36
35
|
|
37
36
|
# Create a configuration file based on a root path
|
38
|
-
def create_config(dir, group=nil)
|
37
|
+
def create_config(dir, group = nil)
|
39
38
|
dir = dir.is_a?(Array) ? dir.first : dir
|
40
|
-
config_file = File.join(dir,
|
39
|
+
config_file = File.join(dir, 'git-projects.yml')
|
41
40
|
group ||= dir.split(File::SEPARATOR).last if dir
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
puts "You can later fetch changes through: git-projects fetch #{group}".green
|
54
|
-
else
|
55
|
-
raise "The config file, #{config_file} exists"
|
42
|
+
fail "The config file, #{config_file} exists" if File.exist?(config_file)
|
43
|
+
|
44
|
+
projects = []
|
45
|
+
Dir.entries(dir)[2..-1].each do |project|
|
46
|
+
g = Git.open(File.join(dir, project))
|
47
|
+
p = {}
|
48
|
+
p[project] = add_remotes_to_hash(g, dir)
|
49
|
+
p[project]['group'] = group
|
50
|
+
projects << p
|
51
|
+
create_yaml_file(config_file, projects)
|
56
52
|
end
|
53
|
+
puts "You can later fetch changes through:
|
54
|
+
\ngit-projects fetch #{group}".green
|
57
55
|
end
|
58
56
|
|
59
|
-
def
|
60
|
-
@project.
|
57
|
+
def create_root_path(path)
|
58
|
+
@project.create_root_path(path)
|
61
59
|
end
|
62
60
|
|
63
61
|
# Create dir unless it exists
|
64
62
|
def create_directory(path)
|
65
|
-
unless File.directory?(path)
|
66
|
-
|
67
|
-
puts "Creating directory: ".green+"#{path}".blue
|
68
|
-
end
|
63
|
+
`mkdir -p #{path}` unless File.directory?(path)
|
64
|
+
puts 'Creating directory: '.green + "#{path}".blue
|
69
65
|
end
|
70
66
|
|
71
67
|
# Create root_dir
|
@@ -76,9 +72,11 @@ class GitProject
|
|
76
72
|
# Check for the config
|
77
73
|
def check_config
|
78
74
|
if ENV['GIT_PROJECTS']
|
79
|
-
puts "Checking repositories. If things go wrong,
|
75
|
+
puts "Checking repositories. If things go wrong,
|
76
|
+
update #{ENV['GIT_PROJECTS']}".green
|
80
77
|
else
|
81
|
-
|
78
|
+
fail "Please add the path your git projects config. \n
|
79
|
+
export GIT_PROJECTS=/path/to/git_projects.yml"
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
@@ -86,7 +84,7 @@ class GitProject
|
|
86
84
|
def clone(url, name, path)
|
87
85
|
r = "#{path}/#{name}"
|
88
86
|
if Git.open(r)
|
89
|
-
puts
|
87
|
+
puts 'Already cloned '.yellow + "#{url}".blue
|
90
88
|
else
|
91
89
|
Git.clone(url, name, path: path) || Git.init(r)
|
92
90
|
g = Git.open(r)
|
@@ -97,47 +95,60 @@ class GitProject
|
|
97
95
|
|
98
96
|
# Add remote
|
99
97
|
def add_remote(g, v)
|
100
|
-
|
98
|
+
unless g.remotes.map(&:name).include?('all')
|
99
|
+
g.add_remote('all', v['origin'])
|
100
|
+
end
|
101
101
|
v.each do |name, remote|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
102
|
+
next if %w(root_dir all group).include?(name) ||
|
103
|
+
g.remotes.map(&:name).include?(name)
|
104
|
+
if g.add_remote(name, remote)
|
105
|
+
# add to all remote
|
106
|
+
# useful when you want to do git push all --all
|
107
|
+
`git remote set-url --add all #{remote}`
|
108
|
+
puts "Added remote #{name}".green
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
def fetch(g
|
113
|
+
def fetch(g)
|
114
114
|
g.remotes.each do |r|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
115
|
+
next if %w(root_dir all group).include?(r.name)
|
116
|
+
r.fetch
|
117
|
+
puts "Fetching updates from #{r.name}: #{r.url}".green
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
122
|
# 1. Clone all repositories based on the origin key
|
124
123
|
# 2. Add all other remotes unless it is origin
|
124
|
+
def create_project_and_remotes(k, v)
|
125
|
+
unless v['root_dir']
|
126
|
+
puts "root_dir isn't defined for #{k}"
|
127
|
+
end
|
128
|
+
unless File.directory?(v['root_dir'])
|
129
|
+
puts "The dir #{v['root_dir']} does not exist"
|
130
|
+
end
|
131
|
+
GitProject.create_root_dir(v['root_dir'])
|
132
|
+
g = GitProject.clone(v.values[0], k, v['root_dir'])
|
133
|
+
GitProject.add_remote(g, v) if g
|
134
|
+
end
|
135
|
+
|
136
|
+
def initialize_and_add_remotes(k, v)
|
137
|
+
g = Git.init("#{v['root_dir']}/#{k}")
|
138
|
+
return nil unless g
|
139
|
+
GitProject.add_remote(g, v)
|
140
|
+
GitProject.fetch(g)
|
141
|
+
end
|
142
|
+
|
125
143
|
def init
|
126
|
-
@project.all.each do |k,v|
|
144
|
+
@project.all.each do |k, v|
|
127
145
|
begin
|
128
|
-
|
129
|
-
puts "The dir #{v['root_dir']} does not exist" unless File.directory?(v['root_dir'])
|
130
|
-
GitProject.create_root_dir(v['root_dir'])
|
131
|
-
g = GitProject.clone(v.values[0], k, v['root_dir'])
|
132
|
-
GitProject.add_remote(g,v) if g
|
146
|
+
create_project_and_remotes(k, v)
|
133
147
|
rescue => e
|
134
|
-
|
135
|
-
if g
|
136
|
-
GitProject.add_remote(g,v)
|
137
|
-
GitProject.fetch(g, v)
|
138
|
-
end
|
148
|
+
initialize_and_add_remotes(k, v)
|
139
149
|
puts "Please check paths and permissions for #{k}. Error: #{e}".red
|
140
|
-
puts "Failed to clone #{v.values[0]}. Initialized &
|
150
|
+
puts "Failed to clone #{v.values[0]}. Initialized &
|
151
|
+
fetched updates from remotes instead.".yellow
|
141
152
|
end
|
142
153
|
end
|
143
154
|
end
|
@@ -158,10 +169,10 @@ class GitProject
|
|
158
169
|
|
159
170
|
# Add missing remotes
|
160
171
|
def add_remotes
|
161
|
-
@project.all.each do |k,v|
|
172
|
+
@project.all.each do |k, v|
|
162
173
|
working_dir = "#{v['root_dir']}/#{k}"
|
163
174
|
g = Git.open(working_dir) || Git.init(working_dir)
|
164
|
-
GitProject.add_remote(g,v)
|
175
|
+
GitProject.add_remote(g, v)
|
165
176
|
puts "Checking new remotes for #{k}".green
|
166
177
|
end
|
167
178
|
end
|
@@ -169,15 +180,13 @@ class GitProject
|
|
169
180
|
# Fetch all updates
|
170
181
|
# Group is optional
|
171
182
|
# By default, fetch from all
|
172
|
-
def fetch_all(group=nil)
|
173
|
-
@project.all(group).each do |k,v|
|
183
|
+
def fetch_all(group = nil)
|
184
|
+
@project.all(group).each do |k, v|
|
174
185
|
puts "Fetching changes for #{k}".green
|
175
186
|
GitProject.create_root_dir(v['root_dir'])
|
176
187
|
working_dir = "#{v['root_dir']}/#{k}"
|
177
188
|
g = Git.open(working_dir) || Git.init(working_dir)
|
178
|
-
GitProject.fetch(g
|
189
|
+
GitProject.fetch(g)
|
179
190
|
end
|
180
|
-
return true
|
181
191
|
end
|
182
|
-
|
183
192
|
end
|
data/lib/helpers/project.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'colorize'
|
3
3
|
|
4
|
+
# Project represents a Git project
|
4
5
|
class Project
|
5
|
-
|
6
|
-
attr :projects
|
6
|
+
attr_reader :projects
|
7
7
|
|
8
8
|
def initialize(config)
|
9
9
|
@projects = YAML.load_file(config)
|
10
10
|
end
|
11
11
|
|
12
|
-
def all(group=nil)
|
13
|
-
group ? @projects.select { |
|
12
|
+
def all(group = nil)
|
13
|
+
group ? @projects.select { |_k, v| v['group'].include?(group) } : @projects
|
14
14
|
end
|
15
15
|
|
16
16
|
def first
|
17
17
|
all.first
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def create_root_path(path)
|
21
21
|
@projects.tap do |project|
|
22
|
-
project.each do |
|
22
|
+
project.each do |_k, v|
|
23
23
|
v['root_dir'] = path
|
24
24
|
end
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-projects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katherine Pe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
19
|
+
version: 1.2.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.
|
26
|
+
version: 1.2.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: colorize
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.2.
|
116
|
+
rubygems_version: 2.2.2
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: Easily manage Git projects
|