git-projects 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145601748d4cda601bc403ea515b76512ab3230f
4
- data.tar.gz: 14f0a8efee0d133ff9e286a3358c47dbe7cb3a1a
3
+ metadata.gz: b3242cc416b633af159ae2c9382e272fa0fcf3e0
4
+ data.tar.gz: c03664dc2621b8ec9bbb539df5738e1f4ffe9dd1
5
5
  SHA512:
6
- metadata.gz: 138dd6c41ae38666eae2efd1ddd3e746183d6dc42961243e3d1b4eda5c1bb7069d7abf7bf6f2733e3b71bd8693455f143d954dec573bcb84e64212709e1d2f8c
7
- data.tar.gz: af62eb78ea5f794107b87cdfada3718a373bdc621b451c33b838ab25fbdbf8668bea6879d6aa55054b549ffddb039e537a07a9057a0dc4c32e4686e15c5d0a1d
6
+ metadata.gz: ee5de45113f5eb7fd93514561a8bbd7b9cc8c164fae9d3b538b7fbd593fdc03923e6ca966714842f9462845b8d36c42e04a3aa272c3556e8e08ea50c4a65f97e
7
+ data.tar.gz: a44f32a3964a5ea591cd30a9f5ef588c2848fceddd3af063b1b110cb143f5db035f4cc932a0c7a37d3b1111eefbc3f9a5c2821d0cf7272f61986a9daeebe4135
@@ -1,3 +1,3 @@
1
1
  module GitProjects
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require_relative 'git_project_config'
2
+ require_relative 'git_project_remote'
1
3
  require_relative 'project'
2
4
  require 'git'
3
5
  require 'yaml'
@@ -7,139 +9,13 @@ require 'colorize'
7
9
  class GitProject
8
10
  attr_reader :project
9
11
 
12
+ include GitProjectConfig
13
+ include GitProjectRemote
14
+
10
15
  def initialize(config)
11
16
  @project = Project.new(config)
12
17
  end
13
18
 
14
- class << self
15
- # Create YAML file
16
- def create_yaml_file(config_file, projects)
17
- File.open(config_file, 'w') do |f|
18
- f.write projects.to_yaml.gsub(/- /, '').gsub(/ /, ' ').gsub(/---/, '')
19
- end
20
- end
21
-
22
- # Create a hash for remotes
23
- def add_remotes_to_hash(g, dir)
24
- remotes_h = {}
25
- r = {}
26
- remotes_h.tap do |remotes|
27
- g.remotes.each do |remote|
28
- r[remote.name] = remote.url
29
- end
30
- r['all'] = true
31
- r['root_dir'] = dir
32
- remotes.merge!(r)
33
- end
34
- end
35
-
36
- # Create a configuration file based on a root path
37
- def create_config(dir, group = nil)
38
- dir = dir.is_a?(Array) ? dir.first : dir
39
- config_file = File.join(dir, 'git-projects.yml')
40
- group ||= dir.split(File::SEPARATOR).last if dir
41
-
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)
52
- end
53
- puts "You can later fetch changes through:
54
- \ngit-projects fetch #{group}".green
55
- end
56
-
57
- def create_root_path(path)
58
- @project.create_root_path(path)
59
- end
60
-
61
- # Create dir unless it exists
62
- def create_directory(path)
63
- `mkdir -p #{path}` unless File.directory?(path)
64
- puts 'Creating directory: '.green + "#{path}".blue
65
- end
66
-
67
- # Create root_dir
68
- def create_root_dir(path)
69
- GitProject.create_directory(path) unless File.directory?(path)
70
- end
71
-
72
- # Check for the config
73
- def check_config
74
- if ENV['GIT_PROJECTS']
75
- puts "Checking repositories. If things go wrong,
76
- update #{ENV['GIT_PROJECTS']}".green
77
- else
78
- fail "Please add the path your git projects config. \n
79
- export GIT_PROJECTS=/path/to/git_projects.yml"
80
- end
81
- end
82
-
83
- # Clone unless dir exists
84
- def clone(url, name, path)
85
- r = "#{path}/#{name}"
86
- if Git.open(r)
87
- puts 'Already cloned '.yellow + "#{url}".blue
88
- else
89
- Git.clone(url, name, path: path) || Git.init(r)
90
- g = Git.open(r)
91
- puts "Cloning #{url} as #{name} into #{path}".green
92
- end
93
- g
94
- end
95
-
96
- # Add remote
97
- def add_remote(g, v)
98
- unless g.remotes.map(&:name).include?('all')
99
- g.add_remote('all', v['origin'])
100
- end
101
- v.each do |name, remote|
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
- end
110
- end
111
- end
112
-
113
- def fetch(g)
114
- g.remotes.each do |r|
115
- next if %w(root_dir all group).include?(r.name)
116
- r.fetch
117
- puts "Fetching updates from #{r.name}: #{r.url}".green
118
- end
119
- end
120
- end
121
-
122
- # 1. Clone all repositories based on the origin key
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
-
143
19
  def init
144
20
  @project.all.each do |k, v|
145
21
  begin
@@ -153,6 +29,13 @@ class GitProject
153
29
  end
154
30
  end
155
31
 
32
+ def initialize_and_add_remotes(k, v)
33
+ g = Git.init("#{v['root_dir']}/#{k}")
34
+ return nil unless g
35
+ GitProject.add_remote(g, v)
36
+ GitProject.fetch(g)
37
+ end
38
+
156
39
  def projects
157
40
  @project.all
158
41
  end
@@ -177,8 +60,18 @@ class GitProject
177
60
  end
178
61
  end
179
62
 
180
- # Fetch all updates
181
- # Group is optional
63
+ # 1. Clone all repositories based on the origin key
64
+ # 2. Add all other remotes unless it is origin
65
+ def create_project_and_remotes(k, v)
66
+ puts "root_dir isn't defined for #{k}" unless v['root_dir']
67
+ unless File.directory?(v['root_dir'])
68
+ puts "The dir #{v['root_dir']} does not exist"
69
+ end
70
+ GitProject.create_root_dir(v['root_dir'])
71
+ g = GitProject.clone(v.values[0], k, v['root_dir'])
72
+ GitProject.add_remote(g, v) if g
73
+ end
74
+
182
75
  # By default, fetch from all
183
76
  def fetch_all(group = nil)
184
77
  @project.all(group).each do |k, v|
@@ -0,0 +1,85 @@
1
+ # Create YML config
2
+ module GitProjectConfig
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ # Create YML config
8
+ module ClassMethods
9
+ def create_root_path(path)
10
+ @project.create_root_path(path)
11
+ end
12
+
13
+ # Create dir unless it exists
14
+ def create_directory(path)
15
+ `mkdir -p #{path}` unless File.directory?(path)
16
+ puts 'Creating directory: '.green + "#{path}".blue
17
+ end
18
+
19
+ # Create root_dir
20
+ def create_root_dir(path)
21
+ GitProject.create_directory(path) unless File.directory?(path)
22
+ end
23
+
24
+ # Check for the config
25
+ def check_config
26
+ if ENV['GIT_PROJECTS']
27
+ puts "Checking repositories. If things go wrong,
28
+ update #{ENV['GIT_PROJECTS']}".green
29
+ else
30
+ fail "Please add the path your git projects config. \n
31
+ export GIT_PROJECTS=/path/to/git_projects.yml"
32
+ end
33
+ end
34
+
35
+ # Create YAML file
36
+ def create_yaml_file(config_file, projects)
37
+ File.open(config_file, 'w') do |f|
38
+ f.write projects.to_yaml.gsub(/- /, '').gsub(/ /, ' ').gsub(/---/, '')
39
+ end
40
+ end
41
+
42
+ # Create a hash for remotes
43
+ def add_remotes_to_hash(g, dir)
44
+ remotes_h = {}
45
+ r = {}
46
+ remotes_h.tap do |remotes|
47
+ g.remotes.each do |remote|
48
+ r[remote.name] = remote.url
49
+ end
50
+ r['all'] = true
51
+ r['root_dir'] = dir
52
+ remotes.merge!(r)
53
+ end
54
+ end
55
+
56
+ # Create has for the project
57
+ def project_info_hash(dir, project, group)
58
+ g = Git.open(File.join(dir, project))
59
+ p = {}
60
+ p.tap do |pr|
61
+ pr[project] = add_remotes_to_hash(g, dir)
62
+ pr[project]['group'] = group
63
+ end
64
+ end
65
+
66
+ def create_project_info_hash(projects, dir, group, config_file)
67
+ Dir.entries(dir)[2..-1].each do |project|
68
+ projects << project_info_hash(dir, project, group)
69
+ create_yaml_file(config_file, projects)
70
+ end
71
+ end
72
+
73
+ # Create a configuration file based on a root path
74
+ def create_config(dir, group = nil)
75
+ dir = dir.is_a?(Array) ? dir.first : dir
76
+ config_file = File.join(dir, 'git-projects.yml')
77
+ group ||= dir.split(File::SEPARATOR).last if dir
78
+ fail "The config file, #{config_file} exists" if File.exist?(config_file)
79
+ projects = []
80
+ create_project_info_hash(projects, dir, group, config_file)
81
+ puts "You can later fetch changes through:
82
+ \ngit-projects fetch #{group}".green
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,50 @@
1
+ # Mostly methods for checking/ adding new remotes
2
+ module GitProjectRemote
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ # Check/ add new remotes
8
+ module ClassMethods
9
+ # Clone unless dir exists
10
+ def clone(url, name, path)
11
+ r = "#{path}/#{name}"
12
+ if Git.open(r)
13
+ puts 'Already cloned '.yellow + "#{url}".blue
14
+ else
15
+ Git.clone(url, name, path: path) || Git.init(r)
16
+ g = Git.open(r)
17
+ puts "Cloning #{url} as #{name} into #{path}".green
18
+ end
19
+ g
20
+ end
21
+
22
+ def fetch(g)
23
+ g.remotes.each do |r|
24
+ next if %w(root_dir all group).include?(r.name)
25
+ r.fetch
26
+ puts "Fetching updates from #{r.name}: #{r.url}".green
27
+ end
28
+ end
29
+
30
+ def remote_exists?(g, name)
31
+ g.remotes.map(&:name).include?(name)
32
+ end
33
+
34
+ def add_new_remote(g, name, remote)
35
+ g.add_remote(name, remote)
36
+ `git remote set-url --add all #{remote}`
37
+ puts "Added remote #{name}".green
38
+ end
39
+
40
+ # Add remote
41
+ def add_remote(g, v)
42
+ g.add_remote('origin', v['origin']) unless remote_exists?(g, 'origin')
43
+ v.each do |name, remote|
44
+ next if %w(root_dir all group).include?(name) ||
45
+ g.remotes.map(&:name).include?(name)
46
+ add_new_remote(g, name, remote)
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-projects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-07-07 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: git
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,13 +39,13 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: 1.2.7
27
41
  - !ruby/object:Gem::Dependency
28
- name: colorize
42
+ name: aruba
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :runtime
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -39,19 +53,19 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: aruba
56
+ name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - '='
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 5.4.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - '='
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 5.4.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +105,8 @@ files:
91
105
  - lib/git-projects.rb
92
106
  - lib/git-projects/version.rb
93
107
  - lib/helpers/git_project.rb
108
+ - lib/helpers/git_project_config.rb
109
+ - lib/helpers/git_project_remote.rb
94
110
  - lib/helpers/project.rb
95
111
  homepage: https://github.com/katgironpe/git-projects
96
112
  licenses: