right_scraper 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,24 +48,27 @@ module RightScale
48
48
  msg += "git repository '#{@repo.display_name}'"
49
49
  @callback.call(msg, is_step=true) if @callback
50
50
  ssh_cmd = ssh_command
51
- is_tag = nil
52
- is_branch = nil
51
+ is_tag = is_branch = on_branch = nil
52
+ has_tag = !@repo.tag.nil? && !@repo.tag.empty?
53
53
 
54
54
  if @incremental
55
55
  Dir.chdir(@current_repo_dir) do
56
56
  analysis = git_fetch_and_analyze(ssh_cmd, update=true)
57
- if succeeded? && @incremental
57
+ if succeeded? && @incremental && has_tag
58
58
  is_tag = analysis[:tag]
59
59
  is_branch = analysis[:branch]
60
+ on_branch = analysis[:on_branch]
60
61
  if !is_tag && !is_branch
61
- @callback.call('Nothing to update: repo tag refers to neither a branch nor a tag', is_step=false) if @callback
62
- return true
62
+ current_sha = `git rev-parse HEAD`.chomp
63
+ if current_sha == @repo.tag
64
+ @callback.call("Nothing to update: already using #{repo.tag}", is_step=false) if @callback
65
+ return true
66
+ end
63
67
  end
64
68
  if is_tag && is_branch
65
69
  @errors << 'Repository tag ambiguous: could be git tag or git branch'
66
- else
67
- tag = @repo.tag.nil? || @repo.tag.empty? ? 'master' : @repo.tag
68
- res = `git checkout #{tag} 2>&1`
70
+ elsif !on_branch
71
+ res = `git checkout #{@repo.tag} 2>&1`
69
72
  if $? != 0
70
73
  @callback.call("Failed to checkout #{tag}: #{res}, falling back to cloning", is_step=false) if @callback
71
74
  FileUtils.rm_rf(@current_repo_dir)
@@ -79,24 +82,27 @@ module RightScale
79
82
  git_cmd = "#{ssh_cmd} git clone --quiet --depth 1 \"#{@repo.url}\" \"#{@current_repo_dir}\" 2>&1"
80
83
  res = @watcher.launch_and_watch(git_cmd, @current_repo_dir)
81
84
  handle_watcher_result(res, 'git clone', update=false)
82
- if !@repo.tag.nil? && !@repo.tag.empty? && @repo.tag != 'master' && succeeded?
85
+ if has_tag && succeeded?
83
86
  Dir.chdir(@current_repo_dir) do
84
87
  if is_tag.nil?
85
- analysis = git_fetch_and_analyze(ssh_cmd, update=false)
86
- is_tag = analysis[:tag]
88
+ analysis = git_fetch_and_analyze(ssh_cmd, update=false)
89
+ is_tag = analysis[:tag]
87
90
  is_branch = analysis[:branch]
91
+ on_branch = analysis[:on_branch]
88
92
  end
89
93
  if succeeded?
90
94
  if is_tag && is_branch
91
95
  @errors << 'Repository tag ambiguous: could be git tag or git branch'
92
- elsif is_branch
93
- output = `git branch #{@repo.tag} origin/#{@repo.tag} 2>&1`
94
- @errors << output if $? != 0
96
+ elsif is_branch
97
+ if !on_branch
98
+ output = `git branch #{@repo.tag} origin/#{@repo.tag} 2>&1`
99
+ @errors << output if $? != 0
100
+ end
95
101
  elsif !is_tag # Not a branch nor a tag, SHA ref? fetch everything so we have all SHAs
96
- output = `#{ssh_cmd} git fetch origin master --depth #{2**31 - 1} 2>&1`
102
+ output = `#{ssh_cmd} git fetch --depth #{2**31 - 1} 2>&1`
97
103
  @errors << output if $? != 0
98
104
  end
99
- if succeeded?
105
+ if succeeded? && !on_branch
100
106
  output = `git checkout #{@repo.tag} 2>&1`
101
107
  @errors << output if $? != 0
102
108
  end
@@ -163,27 +169,27 @@ module RightScale
163
169
  # === Raise
164
170
  # Exception:: If the USERPROFILE environment variable is not set
165
171
  def win32_ssh_command
166
- key_content = @repo.first_credential
167
- unless key_content.nil?
168
- # resolve key file path.
169
- raise 'Environment variable USERPROFILE is missing' unless ENV['USERPROFILE']
170
- user_profile_dir_path = ENV['USERPROFILE']
171
- ssh_keys_dir = File.join(user_profile_dir_path, '.ssh')
172
- FileUtils.mkdir_p(ssh_keys_dir) unless File.directory?(ssh_keys_dir)
173
- ssh_key_file_path = File.join(ssh_keys_dir, 'id_rsa')
174
-
175
- # (re)create key file. must overwrite any existing credentials in case
176
- # we are switching repositories and have different credentials for each.
177
- File.open(ssh_key_file_path, 'w') { |f| f.puts(key_content) }
178
-
179
- # we need to create the "known_hosts" file or else the process will
180
- # halt in windows waiting for a yes/no response to the unknown
181
- # git host. this is normally handled by specifying
182
- # "-o StrictHostKeyChecking=no" in the GIT_SSH executable, but it is
183
- # still a mystery why this doesn't work properly in windows.
184
- # so make a ssh call which creates the proper "known_hosts" file.
185
- system("ssh -o StrictHostKeyChecking=no #{repo.url.split(':').first} exit 2>&1")
186
- end
172
+ key_content = @repo.first_credential
173
+ unless key_content.nil?
174
+ # resolve key file path.
175
+ raise 'Environment variable USERPROFILE is missing' unless ENV['USERPROFILE']
176
+ user_profile_dir_path = ENV['USERPROFILE']
177
+ ssh_keys_dir = File.join(user_profile_dir_path, '.ssh')
178
+ FileUtils.mkdir_p(ssh_keys_dir) unless File.directory?(ssh_keys_dir)
179
+ ssh_key_file_path = File.join(ssh_keys_dir, 'id_rsa')
180
+
181
+ # (re)create key file. must overwrite any existing credentials in case
182
+ # we are switching repositories and have different credentials for each.
183
+ File.open(ssh_key_file_path, 'w') { |f| f.puts(key_content) }
184
+
185
+ # we need to create the "known_hosts" file or else the process will
186
+ # halt in windows waiting for a yes/no response to the unknown
187
+ # git host. this is normally handled by specifying
188
+ # "-o StrictHostKeyChecking=no" in the GIT_SSH executable, but it is
189
+ # still a mystery why this doesn't work properly in windows.
190
+ # so make a ssh call which creates the proper "known_hosts" file.
191
+ system("ssh -o StrictHostKeyChecking=no #{repo.url.split(':').first} exit 2>&1")
192
+ end
187
193
  return ''
188
194
  end
189
195
 
@@ -205,12 +211,13 @@ module RightScale
205
211
  git_cmd = "#{ssh_cmd} git fetch --tags --depth 1 2>&1"
206
212
  res = @watcher.launch_and_watch(git_cmd, @current_repo_dir)
207
213
  handle_watcher_result(res, 'git fetch', update, ok_codes=[0, 1]) # git fetch returns 1 when there is nothing to fetch
208
- is_tag = is_branch = false
214
+ is_tag = is_branch = on_branch = false
209
215
  if succeeded? && (!update || @incremental)
210
216
  is_tag = `git tag`.split("\n").include?(@repo.tag)
211
217
  is_branch = `git branch -r`.split("\n").map { |t| t.strip }.include?("origin/#{@repo.tag}")
218
+ on_branch = is_branch && !!(`git branch`.split("\n").include?("* #{@repo.tag}")
212
219
  end
213
- { :tag => is_tag, :branch => is_branch }
220
+ { :tag => is_tag, :branch => is_branch, :on_branch => on_branch }
214
221
  end
215
222
 
216
223
  end
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
 
24
24
  spec = Gem::Specification.new do |spec|
25
25
  spec.name = 'right_scraper'
26
- spec.version = '1.0.12'
26
+ spec.version = '1.0.13'
27
27
  spec.authors = ['Raphael Simon']
28
28
  spec.email = 'raphael@rightscale.com'
29
29
  spec.homepage = 'https://github.com/rightscale/right_scraper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Simon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-26 00:00:00 -07:00
12
+ date: 2010-04-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15