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 +4 -4
- data/lib/asgit/shell.rb +3 -18
- data/lib/asgit/version.rb +1 -1
- data/lib/asgit.rb +5 -11
- data/spec/lib/asgit/shell_spec.rb +12 -0
- data/spec/lib/asgit_spec.rb +20 -26
- data/spec/spec_helper.rb +14 -10
- data/spec/support/stubbed_shell.rb +11 -0
- metadata +24 -8
- data/spec/support/fake_stdout.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f89a149b2ac9d40a18e93a6f80da4e394901046
|
4
|
+
data.tar.gz: ac6a95bce8a86080ff057908c97ad9ee654e980a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ad454da449e915d67ea0346ce7b3eaf017ccedb2cd51c78f302309a0d5c7db0ec87536b401771bef72c4aeb4112d1e218c14f9a435e31167e5c9bc56a004aa
|
7
|
+
data.tar.gz: d3775c9813be77c6921fc378fa50ba316201ca86b53637cf6d8e2910e15b0dc9af988841df6f1aadc05484b4a0dc5bef4564abf4b22030d92461f24ecd4fdf4d
|
data/lib/asgit/shell.rb
CHANGED
@@ -1,28 +1,13 @@
|
|
1
|
-
require '
|
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
|
9
|
-
|
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
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"
|
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"
|
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"
|
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
|
-
|
37
|
-
return
|
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
|
data/spec/lib/asgit_spec.rb
CHANGED
@@ -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
|
-
|
8
|
-
Asgit
|
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
|
-
|
14
|
-
|
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
|
-
|
22
|
-
Asgit
|
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
|
-
|
31
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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/
|
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 "
|
14
|
+
describe "stub_shell" do
|
11
15
|
it "overrides the actual stdout for Asgit::Shell" do
|
12
|
-
|
13
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
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.
|
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:
|
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/
|
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.
|
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/
|
83
|
+
- spec/support/stubbed_shell.rb
|
data/spec/support/fake_stdout.rb
DELETED
@@ -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
|