asgit 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c28ffc8cb032e8af5e3ea65f5056accba05ce982
4
- data.tar.gz: 561a141bde4cf33c7202b11b742b982e1d2408b0
3
+ metadata.gz: 8f89a149b2ac9d40a18e93a6f80da4e394901046
4
+ data.tar.gz: ac6a95bce8a86080ff057908c97ad9ee654e980a
5
5
  SHA512:
6
- metadata.gz: ab9a787571aba61904b6107a683ccdba5e0d835fa17163904e8ef3b05ab08b5f8f0f0d2136a8b5263932fb4e35bc8b1c96f4b1ad82363dc8b4bf42137cb7326c
7
- data.tar.gz: 0fad5d6dc5debb3d57a15a0d0a5a98c8e70bd12db3fcf79bf697a3db8c4733629efc1a3f042577ea8e0a0dc30008fb2466520b05c070eeae14c12daff0369441
6
+ metadata.gz: d7ad454da449e915d67ea0346ce7b3eaf017ccedb2cd51c78f302309a0d5c7db0ec87536b401771bef72c4aeb4112d1e218c14f9a435e31167e5c9bc56a004aa
7
+ data.tar.gz: d3775c9813be77c6921fc378fa50ba316201ca86b53637cf6d8e2910e15b0dc9af988841df6f1aadc05484b4a0dc5bef4564abf4b22030d92461f24ecd4fdf4d
data/lib/asgit/shell.rb CHANGED
@@ -1,28 +1,13 @@
1
- require 'open3'
1
+ require 'here_or_there'
2
2
 
3
3
  module Asgit
4
4
  module Shell
5
-
6
5
  class << self
7
6
 
8
- def run command, &block
9
- stdout, stderr, status = Open3.capture3(command)
10
-
11
- if status.success?
12
- yield stdout if block_given?
13
- [ true, stdout, stderr ]
14
- else
15
- $stderr.puts "Problem running #{command}"
16
- $stderr.puts stderr
17
- [ false, stdout, stderr ]
18
- end
19
- rescue StandardError => e
20
- $stderr.puts "Problem running '#{command}'"
21
- $stderr.puts "#{e.message}"
22
- $stderr.puts "#{e.backtrace}"
7
+ def run command
8
+ HereOrThere::Local.new.run command
23
9
  end
24
10
 
25
11
  end
26
-
27
12
  end
28
13
  end
data/lib/asgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Asgit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/asgit.rb CHANGED
@@ -9,32 +9,26 @@ module Asgit
9
9
  # Check if working tree is clean
10
10
  # @return [Boolean] true if branch is clean
11
11
  def working_tree_clean?
12
- Shell.run "git status --porcelain" do |output|
13
- return output.empty?
14
- end
12
+ Shell.run( "git status --porcelain" ).stdout.empty?
15
13
  end
16
14
 
17
15
  # Get current git branch based on exec directory
18
16
  # @return [String] the current checked out branch
19
17
  def current_branch
20
- Shell.run "git symbolic-ref HEAD --short" do |output|
21
- return output.strip
22
- end
18
+ Shell.run( "git symbolic-ref HEAD --short" ).stdout.strip
23
19
  end
24
20
 
25
21
  # Get current git commit based on exec directory
26
22
  # @return [String] the current commit level
27
23
  def current_commit
28
- Shell.run "git rev-parse HEAD" do |output|
29
- return output.strip
30
- end
24
+ Shell.run( "git rev-parse HEAD" ).stdout.strip
31
25
  end
32
26
 
33
27
  # Check if branch is in sync with remote
34
28
  # @return [Boolean]
35
29
  def remote_up_to_date?
36
- status, stdout, stderr = Shell.run "git push --dry-run --porcelain"
37
- return status && stdout.match(/#{current_branch}\s+?\[up\sto\sdate\]/)
30
+ resp = Shell.run "git push --dry-run --porcelain"
31
+ return resp.success? && resp.stdout.match(/#{current_branch}\s+?\[up\sto\sdate\]/)
38
32
  end
39
33
 
40
34
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Asgit::Shell do
4
+ describe "::run" do
5
+ it "calls HereOrThere::Local#run with the provided command" do
6
+ expect_any_instance_of(HereOrThere::Local).to receive(:run)
7
+ .with('ls')
8
+
9
+ Asgit::Shell.run 'ls'
10
+ end
11
+ end
12
+ end
@@ -4,51 +4,45 @@ describe Asgit do
4
4
 
5
5
  describe "::working_tree_clean?" do
6
6
  it "is true when nothing to commit" do
7
- expect( Asgit::Shell ).to receive(:run).with('git status --porcelain').and_call_original
8
- Asgit::Shell.fake_stdout "" do
9
- expect( Asgit.working_tree_clean? ).to be_truthy
10
- end
7
+ stub_shell 'git status --porcelain'
8
+ expect( Asgit.working_tree_clean? ).to be_truthy
11
9
  end
12
10
  it "is false when tree isn't clean" do
13
- Asgit::Shell.fake_stdout "M changelog.md\n" do
14
- expect( Asgit.working_tree_clean? ).to be_falsy
15
- end
11
+ stub_shell 'git status --porcelain', stdout: "M changelog.md\n"
12
+ expect( Asgit.working_tree_clean? ).to be_falsy
16
13
  end
17
14
  end
18
15
 
19
16
  describe "::current_branch" do
20
17
  it "returns master when on master" do
21
- expect( Asgit::Shell ).to receive(:run).with('git symbolic-ref HEAD --short').and_call_original
22
- Asgit::Shell.fake_stdout "master\n" do
23
- expect( Asgit.current_branch ).to eq "master"
24
- end
18
+ stub_shell 'git symbolic-ref HEAD --short', stdout: "master\n"
19
+ expect( Asgit.current_branch ).to eq "master"
25
20
  end
26
21
  end
27
22
 
28
23
  describe "::current_commit" do
29
24
  it "returns current commit" do
30
- Asgit::Shell.fake_stdout "12345" do
31
- expect( Asgit.current_commit ).to eq "12345"
32
- end
25
+ stub_shell 'git rev-parse HEAD', stdout: 'commit_sha'
26
+ expect( Asgit.current_commit ).to eq 'commit_sha'
33
27
  end
34
28
  end
35
29
 
36
30
  describe "::remote_up_to_date?" do
37
31
  it "returns true if remote is current" do
38
- Asgit::Shell.fake_stdout "To git@github.com:stevenosloan/asgit.git\n" +
39
- "=\tHEAD:refs/heads/master\t[up to date]\n" +
40
- "Done\n" do
41
- allow( Asgit ).to receive(:current_branch).and_return("master")
42
- expect( Asgit.remote_up_to_date? ).to be_truthy
43
- end
32
+ stub_shell 'git push --dry-run --porcelain',
33
+ stdout: "To git@github.com:stevenosloan/asgit.git\n" +
34
+ "=\tHEAD:refs/heads/master\t[up to date]\n" +
35
+ "Done\n"
36
+ allow( Asgit ).to receive(:current_branch).and_return("master")
37
+ expect( Asgit.remote_up_to_date? ).to be_truthy
44
38
  end
45
39
  it "returns false if remote is out of sync" do
46
- Asgit::Shell.fake_stdout "To git@github.com:stevenosloan/asgit.git\n" +
47
- "\tHEAD:refs/heads/master\t5871eb5..0ce6c7f\n" +
48
- "Done\n" do
49
- allow( Asgit ).to receive(:current_branch).and_return("master")
50
- expect( Asgit.remote_up_to_date? ).to be_falsy
51
- end
40
+ stub_shell 'git push --dry-run --porcelain',
41
+ stdout: "To git@github.com:stevenosloan/asgit.git\n" +
42
+ "\tHEAD:refs/heads/master\t5871eb5..0ce6c7f\n" +
43
+ "Done\n"
44
+ allow( Asgit ).to receive(:current_branch).and_return("master")
45
+ expect( Asgit.remote_up_to_date? ).to be_falsy
52
46
  end
53
47
  end
54
48
 
data/spec/spec_helper.rb CHANGED
@@ -3,22 +3,26 @@ require 'pry-debugger'
3
3
 
4
4
  require 'asgit'
5
5
 
6
- require 'support/fake_stdout'
6
+ require 'support/stubbed_shell'
7
7
  require 'support/eat_stdout'
8
8
 
9
+ RSpec.configure do |config|
10
+ config.include StubbedShell
11
+ end
12
+
9
13
  describe "spec_helper" do
10
- describe "Asgit::Shell.fake_stdout" do
14
+ describe "stub_shell" do
11
15
  it "overrides the actual stdout for Asgit::Shell" do
12
- Asgit::Shell.fake_stdout "woo" do
13
- expect( Asgit::Shell.run("foo")[1] ).to eq "woo"
14
- end
16
+ stub_shell 'foo', stdout: 'woo'
17
+ expect( Asgit::Shell.run('foo').stdout ).to eq 'woo'
15
18
  end
16
- end
17
- describe "Asgit::Shell.fake_stderr" do
18
19
  it "overrides the actual stderr for Asgit::Shell" do
19
- Asgit::Shell.fake_stderr "woo" do
20
- expect( Asgit::Shell.run("foo")[2] ).to eq "woo"
21
- end
20
+ stub_shell 'foo', stderr: 'woo'
21
+ expect( Asgit::Shell.run('foo').stderr ).to eq 'woo'
22
+ end
23
+ it "overrides the actual status for Asgit::Shell" do
24
+ stub_shell 'foo', status: false
25
+ expect( Asgit::Shell.run('foo').success? ).to be_falsy
22
26
  end
23
27
  end
24
28
  end
@@ -0,0 +1,11 @@
1
+ module StubbedShell
2
+ def stub_shell command, options={}
3
+ stdout = options.fetch(:stdout, '')
4
+ stderr = options.fetch(:stderr, '')
5
+ status = options.fetch(:status, true)
6
+
7
+ expect( Asgit::Shell ).to receive(:run)
8
+ .with(command)
9
+ .and_return( HereOrThere::Response.new( stdout, stderr, status ) )
10
+ end
11
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-31 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: here_or_there
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
13
27
  description: ' A simple query interface for git. '
14
28
  email:
15
29
  - stevenosloan@gmail.com
@@ -17,22 +31,23 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - lib/asgit.rb
20
35
  - lib/asgit/project.rb
36
+ - lib/asgit/services.rb
21
37
  - lib/asgit/services/bitbucket.rb
22
38
  - lib/asgit/services/github.rb
23
39
  - lib/asgit/services/service.rb
24
- - lib/asgit/services.rb
25
40
  - lib/asgit/shell.rb
26
41
  - lib/asgit/url.rb
27
42
  - lib/asgit/version.rb
28
- - lib/asgit.rb
29
43
  - spec/lib/asgit/project_spec.rb
30
44
  - spec/lib/asgit/services_spec.rb
45
+ - spec/lib/asgit/shell_spec.rb
31
46
  - spec/lib/asgit/url_spec.rb
32
47
  - spec/lib/asgit_spec.rb
33
48
  - spec/spec_helper.rb
34
49
  - spec/support/eat_stdout.rb
35
- - spec/support/fake_stdout.rb
50
+ - spec/support/stubbed_shell.rb
36
51
  homepage: http://github.com/stevenosloan/asgit
37
52
  licenses:
38
53
  - MIT
@@ -53,15 +68,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
68
  version: '0'
54
69
  requirements: []
55
70
  rubyforge_project:
56
- rubygems_version: 2.1.11
71
+ rubygems_version: 2.2.0
57
72
  signing_key:
58
73
  specification_version: 4
59
74
  summary: A simple query interface for git
60
75
  test_files:
61
76
  - spec/lib/asgit/project_spec.rb
62
77
  - spec/lib/asgit/services_spec.rb
78
+ - spec/lib/asgit/shell_spec.rb
63
79
  - spec/lib/asgit/url_spec.rb
64
80
  - spec/lib/asgit_spec.rb
65
81
  - spec/spec_helper.rb
66
82
  - spec/support/eat_stdout.rb
67
- - spec/support/fake_stdout.rb
83
+ - spec/support/stubbed_shell.rb
@@ -1,48 +0,0 @@
1
- module Asgit
2
- module Shell
3
- class << self
4
-
5
- def fake_stdout out
6
- set_stdout out
7
- yield
8
- ensure
9
- unset_stdout
10
- end
11
-
12
- def fake_stderr err
13
- set_stderr err
14
- yield
15
- ensure
16
- unset_stderr
17
- end
18
-
19
- def patched_run command, &block
20
- if @shell_out || @shell_err
21
- yield @shell_out if block_given?
22
- [ true, @shell_out || '', @shell_err || '' ]
23
- else
24
- system_run command, &block
25
- end
26
- end
27
-
28
- def set_stdout out
29
- @shell_out = out
30
- end
31
-
32
- def unset_stdout
33
- @shell_out = nil
34
- end
35
-
36
- def set_stderr err
37
- @shell_err = err
38
- end
39
-
40
- def unset_stderr
41
- @shell_err = nil
42
- end
43
-
44
- alias_method :system_run, :run
45
- alias_method :run, :patched_run
46
- end
47
- end
48
- end