webmat-git_remote_branch 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ module CaptureFu
2
+ VERSION = '0.0.1'
3
+
4
+ def capture_output(&block)
5
+ real_out, real_err = $stdout, $stderr
6
+ result = fake_out = fake_err = nil
7
+ begin
8
+ fake_out, fake_err = Helpers::PipeStealer.new, Helpers::PipeStealer.new
9
+ $stdout, $stderr = fake_out, fake_err
10
+ result = yield
11
+ ensure
12
+ $stdout, $stderr = real_out, real_err
13
+ end
14
+ return result, fake_out.captured, fake_err.captured
15
+ end
16
+
17
+ # This first implementation is only intended for batch executions.
18
+ # You can't pipe stuff programmatically to the child process.
19
+ def capture_process_output(command)
20
+
21
+ #capture stderr in the same stream
22
+ command << ' 2>&1' unless Helpers.stderr_already_redirected(command)
23
+
24
+ out = `#{command}`
25
+ return $?.exitstatus, out
26
+ end
27
+
28
+
29
+ private
30
+
31
+ module Helpers
32
+
33
+ def self.stderr_already_redirected(command)
34
+ #Already redirected to stdout (valid for Windows)
35
+ return true if command =~ /2>&1\s*\Z/
36
+
37
+ #Redirected to /dev/null (this is clearly POSIX-dependent)
38
+ return true if command =~ /2>\/dev\/null\s*\Z/
39
+
40
+ return false
41
+ end
42
+
43
+ class PipeStealer < File
44
+ attr_reader :captured
45
+ def initialize
46
+ @captured = ''
47
+ end
48
+ def write(s)
49
+ @captured << s
50
+ end
51
+ def captured
52
+ return nil if @captured.empty?
53
+ @captured.dup
54
+ end
55
+ end
56
+
57
+ end #Helper module
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmat-git_remote_branch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Martin
@@ -10,11 +10,12 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-07-08 00:00:00 -07:00
13
+ date: 2008-08-05 21:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: colored
18
+ type: :runtime
18
19
  version_requirement:
19
20
  version_requirements: !ruby/object:Gem::Requirement
20
21
  requirements:
@@ -31,15 +32,39 @@ extensions: []
31
32
  extra_rdoc_files: []
32
33
 
33
34
  files:
34
- - Rakefile
35
- - README
36
- - TODO
35
+ - bin
37
36
  - bin/grb
37
+ - CHANGELOG
38
+ - COPYING
39
+ - lib
38
40
  - lib/git_remote_branch.rb
39
41
  - lib/param_reader.rb
40
- - test/git_helper.rb
42
+ - lib/version.rb
43
+ - Rakefile
44
+ - README
45
+ - tasks
46
+ - tasks/gem.rake
47
+ - tasks/test.rake
48
+ - test
49
+ - test/functional
50
+ - test/functional/grb_test.rb
51
+ - test/helpers
52
+ - test/helpers/array_extensions.rb
53
+ - test/helpers/dir_stack.rb
54
+ - test/helpers/extractable.rb
55
+ - test/helpers/git_helper.rb
56
+ - test/helpers/more_assertions.rb
57
+ - test/helpers/shoulda_functional_helpers.rb
58
+ - test/helpers/shoulda_unit_helpers.rb
59
+ - test/helpers/temp_dir_helper.rb
41
60
  - test/test_helper.rb
61
+ - test/unit
42
62
  - test/unit/git_helper_test.rb
63
+ - test/unit/git_remote_branch_test.rb
64
+ - test/unit/param_reader_test.rb
65
+ - TODO
66
+ - vendor
67
+ - vendor/capture_fu.rb
43
68
  has_rdoc: false
44
69
  homepage: http://github.com/webmat/git_remote_branch
45
70
  post_install_message:
@@ -61,12 +86,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
86
  version:
62
87
  requirements: []
63
88
 
64
- rubyforge_project:
89
+ rubyforge_project: grb
65
90
  rubygems_version: 1.2.0
66
91
  signing_key:
67
92
  specification_version: 2
68
93
  summary: git_remote_branch eases the interaction with remote branches
69
94
  test_files:
70
- - test/git_helper.rb
95
+ - test/functional
96
+ - test/functional/grb_test.rb
97
+ - test/helpers
98
+ - test/helpers/array_extensions.rb
99
+ - test/helpers/dir_stack.rb
100
+ - test/helpers/extractable.rb
101
+ - test/helpers/git_helper.rb
102
+ - test/helpers/more_assertions.rb
103
+ - test/helpers/shoulda_functional_helpers.rb
104
+ - test/helpers/shoulda_unit_helpers.rb
105
+ - test/helpers/temp_dir_helper.rb
71
106
  - test/test_helper.rb
107
+ - test/unit
72
108
  - test/unit/git_helper_test.rb
109
+ - test/unit/git_remote_branch_test.rb
110
+ - test/unit/param_reader_test.rb
data/test/git_helper.rb DELETED
@@ -1,57 +0,0 @@
1
- require 'fileutils'
2
- require 'tmpdir'
3
-
4
- # Instantiating a GitHelper object creates a temp directory containing 3 repos.
5
- # 1 that's considered the remote repo and 2 peer local repos (local1 and local2).
6
- # All 3 are synchronized with the same data (they contain a few dummy files).
7
- # Once instantiated you can access the 3 full repo locations through attribute readers
8
- # remote, local1 and local2.
9
- class GitHelper
10
- include FileUtils
11
-
12
- @@WORK_DIR = 'repo_test'
13
-
14
- attr_reader :remote, :local1, :local2
15
-
16
- def initialize
17
- @wd = get_temp_dir
18
-
19
- @remote = init_repo(@wd, 'remote')
20
- @local1 = clone_repo(@remote, @wd, 'local1')
21
- @local2 = clone_repo(@remote, @wd, 'local2')
22
- end
23
-
24
- def cleanup
25
- rm_rf @wd
26
- end
27
-
28
- protected
29
- def get_temp_dir
30
- #Note: it's NOT a good idea to do this stuff un a subdirectory of the
31
- #git_remote_branch repo. Trust me :-)
32
- wd = File.expand_path( File.join( Dir::tmpdir, @@WORK_DIR) )
33
- Dir.mkdir wd unless File.exists? wd
34
-
35
- #Create new subdir with a random name
36
- new_dir=''
37
- begin
38
- new_dir = File.join( wd, "#{rand(10000)}" )
39
- Dir.mkdir new_dir
40
- rescue
41
- retry
42
- end
43
-
44
- new_dir
45
- end
46
-
47
- def init_repo(path, name)
48
- repo_dir = File.join(path, name)
49
- `mkdir #{repo_dir}; cd $_; git init; touch file.txt; git add .; git commit -a -m "dummy file"`
50
- repo_dir
51
- end
52
-
53
- def clone_repo(origin_path, clone_path, name)
54
- `cd #{clone_path}; git clone #{File.join(origin_path, '.git')} #{name}`
55
- return File.join(clone_path, name)
56
- end
57
- end