obazoud-git-external 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/git-external +45 -21
  2. metadata +5 -5
data/bin/git-external CHANGED
@@ -70,7 +70,7 @@ def load_configuration(file)
70
70
  linesExit, lines = execute('git config', ['--list', '--file', file])
71
71
  lines.each do |line|
72
72
  if line =~ /^external\.([^$]+)\.([^=]+)=(.*)$/
73
- $configurations[$1.chomp] ||= {}
73
+ $configurations[$1.chomp] ||= {'revision' => false}
74
74
  $configurations[$1.chomp][$2.chomp] = $3.chomp
75
75
  end
76
76
  end
@@ -100,35 +100,47 @@ def branch_exists(path, branch)
100
100
  return result
101
101
  end
102
102
 
103
- def init_external(url, path, branch='master')
103
+ def init_external(url, path, branch='origin/master', revision=nil)
104
104
  require 'fileutils'
105
105
  if File.directory? "#{path}/.git"
106
106
  puts "- Repository already exists"
107
- else
108
- FileUtils.makedirs File.dirname(path)
109
- url = normalize_url url
110
- execute('git clone', ["#{url}", path], Dir.getwd, '')
107
+
108
+ return
109
+ end
110
+
111
+ url = normalize_url url
112
+ execute('git clone', ["#{url}", path], Dir.getwd, '')
113
+
114
+ if not revision
115
+ remoteName, remoteBranch = branch.split('/')
111
116
 
112
117
  # Create a local tracking branch if it doesn't exist already
113
118
  unless branch_exists(path, branch)
114
- puts "- Creating local tracking branch: #{branch} -> origin/#{branch}"
115
- execute('git branch', ['checkout', '--track', "#{branch}", "origin/#{branch}"], path)
119
+ puts "- Creating local tracking branch: #{branch} -> #{remoteBranch}"
120
+ execute('git branch', ['checkout', '--track', "#{remoteBranch}", "#{branch}"], path)
116
121
  end
117
-
118
- # Check out the local branch
119
- puts "- Checkout local branch: #{branch}"
120
- execute('git checkout', ["#{branch}"], path)
122
+
123
+ update_external(url, path, branch, revision)
124
+
125
+ else
126
+ puts "- Dealing with a tag/sha1: #{branch}"
127
+ update_external(url, path, branch, revision)
121
128
  end
129
+
122
130
  end
123
131
 
124
- def update_external(url, path, branch='master')
132
+ def update_external(url, path, branch='origin/master', revision=nil)
125
133
  require 'fileutils'
126
134
  puts "- Updating #{path}"
127
135
  if File.directory? "#{path}/.git"
128
136
  if uncommitted_changes?(path)
129
137
  puts "#{path} - uncommitted changes detected, can not update repository"
138
+ elsif revision
139
+ puts "#{path} - updating to revision:#{revision}"
140
+ execute('git checkout', [revision], path, '')
130
141
  else
131
- execute('git pull', ['origin', "#{branch}"], path, '')
142
+ puts "#{path} - updating branch #{branch}"
143
+ execute('git pull', ['--rebase'], path, '')
132
144
  end
133
145
  end
134
146
  end
@@ -136,11 +148,19 @@ end
136
148
  def command_status
137
149
  ok = 0
138
150
  broken = 0
151
+ unknown = 0
139
152
  $configurations.each do |name, config|
140
153
  branch = config["branch"]
141
154
  url = config["url"]
142
155
  path = config["path"]
156
+ revision = config["revision"]
143
157
 
158
+ # not implemented yet
159
+ if revision
160
+ unknown += 1
161
+ next
162
+ end
163
+
144
164
  symbolicExit, symbolic = execute('git symbolic-ref', ['HEAD', '--short'], path)
145
165
  gitBranchExit, gitBranch = execute('git config', ["branch.#{symbolic}.merge"], path)
146
166
  gitBranch = gitBranch.gsub('refs/heads/', '')
@@ -153,11 +173,13 @@ def command_status
153
173
  changesString = ""
154
174
  end
155
175
 
176
+ remoteBranch = remote + "/" + gitBranch
177
+
156
178
  if gitBranchExit != 0 && gitBranchExit != 1 && gitRemoteExit != 0 && gitRemoteExit != 1
157
179
  puts " ✗ #{path} -- exit code #{gitBranchExit}, #{gitRemoteExit}"
158
180
  broken += 1
159
181
  else
160
- if branch == gitBranch
182
+ if branch == remoteBranch
161
183
  if url == gitRemote
162
184
  puts " ✓ #{path} #{changesString}"
163
185
  ok += 1
@@ -166,15 +188,16 @@ def command_status
166
188
  broken +=1
167
189
  end
168
190
  else
169
- puts " ✗ #{path} #{changesString} -- expected branch '#{branch}' but was '#{gitBranch}'"
191
+ puts " ✗ #{path} #{changesString} -- expected branch '#{branch}' but was '#{remoteBranch}'"
170
192
  broken +=1
171
193
  end
172
194
  end
173
195
  end
174
- puts "#{broken > 0 ? "✗" : "✓"} » #{ok} ok • #{broken} broken"
196
+
197
+ puts "#{broken > 0 ? "✗" : "✓"} » #{ok} ok • #{broken} broken - #{unknown} unknown"
175
198
  end
176
199
 
177
- def command_add(url, path, branch='master')
200
+ def command_add(url, path, branch='origin/master')
178
201
  command_rm(path)
179
202
  execute('git config', ['--file', $externals_file, '--add', "external.#{path}.path", "#{path}"])
180
203
  execute('git config', ['--file', $externals_file, '--add', "external.#{path}.url", "#{url}"])
@@ -190,6 +213,7 @@ def command_rm(path)
190
213
  execute('git config', ['--file', $externals_file, '--unset', "external.#{path}.path"])
191
214
  execute('git config', ['--file', $externals_file, '--unset', "external.#{path}.url"])
192
215
  execute('git config', ['--file', $externals_file, '--unset', "external.#{path}.branch"])
216
+ execute('git config', ['--file', $externals_file, '--unset', "external.#{path}.revision"])
193
217
  execute('git config', ['--file', $externals_file, '--remove-section', "external.#{path}"])
194
218
 
195
219
  if File.file? $ignore_file
@@ -207,13 +231,13 @@ end
207
231
  def command_init
208
232
  $configurations.each do |name, config|
209
233
  puts name
210
- init_external config["url"], config["path"], config["branch"]
234
+ init_external config["url"], config["path"], config["branch"], config['revision']
211
235
  end
212
236
  end
213
237
 
214
238
  def command_update
215
239
  $configurations.each do |name, config|
216
- update_external config["url"], config["path"], config["branch"]
240
+ update_external config["url"], config["path"], config["branch"], config['revision']
217
241
  end
218
242
  end
219
243
 
@@ -268,7 +292,7 @@ command=ARGV[0]
268
292
 
269
293
  case command
270
294
  when "status" then command_status
271
- when "add" then command_add ARGV[1], ARGV[2], ARGV[3] || "master"
295
+ when "add" then command_add ARGV[1], ARGV[2], ARGV[3] || "origin/master"
272
296
  when "rm" then command_rm ARGV[1]
273
297
  when "init" then command_init
274
298
  when "update" then command_update
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obazoud-git-external
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Cestari
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-10-28 00:00:00 Z
20
+ date: 2012-11-02 00:00:00 Z
21
21
  dependencies: []
22
22
 
23
23
  description: Extension for git which adds a command providing similar functionality to git submodules but without attaching each module to a single version