perforce 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/perforce.rb CHANGED
@@ -163,11 +163,11 @@ class Perforce
163
163
  def root
164
164
  dir = run(*%w(client -o)).first["Root"]
165
165
  if CYGWIN
166
- unix_dir = Util.unix_path(dir)
167
- if dir != unix_dir
168
- add_unix_root
169
- end
170
- unix_dir
166
+ Util.unix_path(dir).tap { |unix_dir|
167
+ if dir != unix_dir
168
+ add_unix_root
169
+ end
170
+ }
171
171
  else
172
172
  dir
173
173
  end
@@ -198,13 +198,28 @@ class Perforce
198
198
  #
199
199
  # Change working directory (locally and remotely).
200
200
  #
201
+ # If a block is given, the original working directory is restored
202
+ # when the block exits. (Behavior is like Dir.chdir.)
203
+ #
201
204
  def chdir(dir)
202
205
  previous_dir = File.expand_path(".")
203
- Dir.chdir(dir) {
206
+
207
+ Dir.chdir(dir)
208
+ begin
204
209
  @p4.cwd = File.expand_path(".")
205
- yield
206
- }
207
- @p4.cwd = previous_dir
210
+ rescue
211
+ Dir.chdir(previous_dir)
212
+ raise
213
+ end
214
+
215
+ if block_given?
216
+ begin
217
+ yield dir
218
+ ensure
219
+ Dir.chdir(previous_dir)
220
+ @p4.cwd = previous_dir
221
+ end
222
+ end
208
223
  end
209
224
 
210
225
  #
@@ -231,8 +246,9 @@ class Perforce
231
246
  if CYGWIN
232
247
  begin
233
248
  go.call
234
- rescue P4Exception
235
- if @p4.connected?
249
+ rescue P4Exception => exception
250
+ if @p4.connected? and
251
+ exception.message =~ %r!not under client\'s root!
236
252
  # maybe unix root is not present; try again
237
253
  add_unix_root
238
254
  go.call
data/perforce.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new { |t|
3
3
  t.name = "perforce"
4
- t.version = "0.5.0"
4
+ t.version = "1.0.0"
5
5
  t.summary = "Streamlined wrapper for p4ruby"
6
6
  t.author = "James M. Lawrence"
7
7
  t.email = "quixoticsycophant@gmail.com"
data/test/test_main.rb CHANGED
@@ -1,6 +1,12 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ begin
4
+ require 'perforce'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'perforce'
8
+ end
1
9
 
2
- require 'rubygems'
3
- require 'perforce'
4
10
  require 'pp'
5
11
 
6
12
  def report(desc)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-07 00:00:00 -04:00
12
+ date: 2008-09-08 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency