story_branch-git_wrapper 0.0.1 → 0.0.3
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/.github/workflows/standard.yml +13 -0
- data/.github/workflows/tests.yml +19 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +58 -0
- data/Rakefile +2 -1
- data/bin/console +1 -1
- data/lib/story_branch/git/version.rb +5 -0
- data/lib/story_branch/git/wrapper.rb +102 -0
- data/lib/story_branch/git.rb +7 -0
- data/story_branch-git_wrapper.gemspec +6 -4
- metadata +38 -6
- data/lib/story_branch/git_wrapper/version.rb +0 -5
- data/lib/story_branch/git_wrapper.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a76df6d72cd3bd6acb33a19807b92f4fea967bf1ad650909d6b30352522a92f
|
4
|
+
data.tar.gz: ece50978f9315af05f54702e446ea756a9461e7db633061e9c2be4690fab560b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7345c2b4ebf37683c30ce51daf591ffb2d05896d44c95393456e7aa099b9789c9beb1be47c4a046bb927c3644551ca27112bd0c73800ec412725e27509be2a81
|
7
|
+
data.tar.gz: fa4867fc1018767800172b1335db0ee7370b622d6505576f7ffb99b3346be7b52e5847e0a8d1004a12b6f967ab52ea4efb9a4b9394b7978275116c83b5410425
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: Checkout
|
10
|
+
uses: actions/checkout@v3
|
11
|
+
|
12
|
+
- name: Setup Ruby
|
13
|
+
uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7
|
16
|
+
bundler-cache: true
|
17
|
+
|
18
|
+
- name: Run tests
|
19
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
story_branch-git_wrapper (0.0.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
ast (2.4.2)
|
11
|
+
builder (3.2.4)
|
12
|
+
json (2.6.2)
|
13
|
+
minitest (5.16.2)
|
14
|
+
minitest-reporters (1.5.0)
|
15
|
+
ansi
|
16
|
+
builder
|
17
|
+
minitest (>= 5.0)
|
18
|
+
ruby-progressbar
|
19
|
+
parallel (1.22.1)
|
20
|
+
parser (3.1.2.1)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
rainbow (3.1.1)
|
23
|
+
rake (12.3.3)
|
24
|
+
regexp_parser (2.5.0)
|
25
|
+
rexml (3.2.5)
|
26
|
+
rubocop (1.33.0)
|
27
|
+
json (~> 2.3)
|
28
|
+
parallel (~> 1.10)
|
29
|
+
parser (>= 3.1.0.0)
|
30
|
+
rainbow (>= 2.2.2, < 4.0)
|
31
|
+
regexp_parser (>= 1.8, < 3.0)
|
32
|
+
rexml (>= 3.2.5, < 4.0)
|
33
|
+
rubocop-ast (>= 1.19.1, < 2.0)
|
34
|
+
ruby-progressbar (~> 1.7)
|
35
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
36
|
+
rubocop-ast (1.21.0)
|
37
|
+
parser (>= 3.1.1.0)
|
38
|
+
rubocop-performance (1.14.3)
|
39
|
+
rubocop (>= 1.7.0, < 2.0)
|
40
|
+
rubocop-ast (>= 0.4.0)
|
41
|
+
ruby-progressbar (1.11.0)
|
42
|
+
standard (1.15.0)
|
43
|
+
rubocop (= 1.33.0)
|
44
|
+
rubocop-performance (= 1.14.3)
|
45
|
+
unicode-display_width (2.2.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
minitest (~> 5.0)
|
52
|
+
minitest-reporters (~> 1.5)
|
53
|
+
rake (~> 12.0)
|
54
|
+
standard (~> 1.15)
|
55
|
+
story_branch-git_wrapper!
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "story_branch/
|
4
|
+
require "story_branch/git"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StoryBranch
|
4
|
+
module Git
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class Wrapper
|
8
|
+
STATI_MATCHERS = {
|
9
|
+
modified_rx: /^ M (.*)/,
|
10
|
+
untracked_rx: /^\?\? (.*)/,
|
11
|
+
staged_rx: /^M (.*)/,
|
12
|
+
added_rx: /^A (.*)/
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def self.command(cmd, opts = [])
|
16
|
+
gw = new
|
17
|
+
gw.execute(cmd, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.command_lines(cmd, opts = [])
|
21
|
+
result = command(cmd, opts)
|
22
|
+
lines = result.split("\n")
|
23
|
+
lines.each(&:strip!)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.branch_names
|
27
|
+
# NOTE: Regex matcher for cases as:
|
28
|
+
# remotes/origin/allow.... <- remote branch (remove 'remotes/origin')
|
29
|
+
# * allow.... <- * indicates current branch (remove '* ')
|
30
|
+
# allow <- local branch (do nothing)
|
31
|
+
regex = %r{(^remotes/.*/|\s|[*])}
|
32
|
+
all_branches.map do |line|
|
33
|
+
line = line.sub(regex, "")
|
34
|
+
line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.current_branch
|
39
|
+
current_branch_line = all_branches.detect do |line|
|
40
|
+
line.match(/\*/)
|
41
|
+
end
|
42
|
+
current_branch_line.tr("*", " ").strip
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.all_branches
|
46
|
+
command_lines("branch", "-a")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.create_branch(name)
|
50
|
+
command("checkout", ["-b", name])
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.status
|
54
|
+
g_status = command_lines("status", "-s")
|
55
|
+
return nil if g_status.empty?
|
56
|
+
|
57
|
+
{
|
58
|
+
modified: status_collect(g_status, STATI_MATCHERS[:modified_rx]),
|
59
|
+
untracked: status_collect(g_status, STATI_MATCHERS[:untracked_rx]),
|
60
|
+
added: status_collect(g_status, STATI_MATCHERS[:added_rx]),
|
61
|
+
staged: status_collect(g_status, STATI_MATCHERS[:staged_rx])
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.status_collect(status, regex)
|
66
|
+
chosen_stati = status.select { |e| e.match(regex) }
|
67
|
+
chosen_stati.map { |e| e.match(regex)[1] }
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.commit(message)
|
71
|
+
command("commit", ["-m", message])
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize
|
75
|
+
@system_git = "git"
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute(cmd, opts = [])
|
79
|
+
opts = prepare_opts(opts)
|
80
|
+
git_cmd = "#{@system_git} #{cmd} #{opts}"
|
81
|
+
|
82
|
+
`#{git_cmd}`.chomp.strip
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# NOTE: Taken from ruby git gem
|
88
|
+
def escape(str = "")
|
89
|
+
str = str.to_s
|
90
|
+
return "'#{str.gsub("\'", '\'"\'"\'')}'" if /mingw|mswin/.match?(RUBY_PLATFORM)
|
91
|
+
|
92
|
+
# Keeping the old escape format for windows users
|
93
|
+
escaped = str.gsub("\'", "\'\\\'\'")
|
94
|
+
%("#{escaped}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def prepare_opts(opts = [])
|
98
|
+
[opts].flatten.map { |s| escape(s) }.join(" ")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require_relative "lib/story_branch/
|
1
|
+
require_relative "lib/story_branch/git/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "story_branch-git_wrapper"
|
5
|
-
spec.version = StoryBranch::
|
5
|
+
spec.version = StoryBranch::Git::VERSION
|
6
6
|
spec.authors = ["Rui Baltazar"]
|
7
7
|
spec.email = ["rui.p.baltazar@gmail.com"]
|
8
8
|
|
9
|
-
spec.summary = "
|
9
|
+
spec.summary = "Git::Wrapper to help running git commands with direct system calls"
|
10
10
|
spec.description = <<~DESCRIPTION
|
11
|
-
|
11
|
+
Git::Wrapper provides a series of commands that wrap actual git commands and processes the output
|
12
12
|
DESCRIPTION
|
13
13
|
spec.homepage = "https://github.com/story-branch/git_wrapper"
|
14
14
|
spec.license = "MIT"
|
@@ -31,5 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
+
spec.add_development_dependency "minitest", "~> 5.16"
|
35
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.5"
|
34
36
|
spec.add_development_dependency "standard", "~> 1.15"
|
35
37
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: story_branch-git_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rui Baltazar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest-reporters
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: standard
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,7 +52,7 @@ dependencies:
|
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.15'
|
27
|
-
description: '
|
55
|
+
description: 'Git::Wrapper provides a series of commands that wrap actual git commands
|
28
56
|
and processes the output
|
29
57
|
|
30
58
|
'
|
@@ -34,18 +62,22 @@ executables: []
|
|
34
62
|
extensions: []
|
35
63
|
extra_rdoc_files: []
|
36
64
|
files:
|
65
|
+
- ".github/workflows/standard.yml"
|
66
|
+
- ".github/workflows/tests.yml"
|
37
67
|
- ".gitignore"
|
38
68
|
- ".travis.yml"
|
39
69
|
- ".vscode/settings.json"
|
40
70
|
- CODE_OF_CONDUCT.md
|
41
71
|
- Gemfile
|
72
|
+
- Gemfile.lock
|
42
73
|
- LICENSE.txt
|
43
74
|
- README.md
|
44
75
|
- Rakefile
|
45
76
|
- bin/console
|
46
77
|
- bin/setup
|
47
|
-
- lib/story_branch/
|
48
|
-
- lib/story_branch/
|
78
|
+
- lib/story_branch/git.rb
|
79
|
+
- lib/story_branch/git/version.rb
|
80
|
+
- lib/story_branch/git/wrapper.rb
|
49
81
|
- story_branch-git_wrapper.gemspec
|
50
82
|
homepage: https://github.com/story-branch/git_wrapper
|
51
83
|
licenses:
|
@@ -74,5 +106,5 @@ requirements: []
|
|
74
106
|
rubygems_version: 3.1.6
|
75
107
|
signing_key:
|
76
108
|
specification_version: 4
|
77
|
-
summary:
|
109
|
+
summary: Git::Wrapper to help running git commands with direct system calls
|
78
110
|
test_files: []
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require "story_branch/git_wrapper/version"
|
2
|
-
|
3
|
-
module StoryBranch
|
4
|
-
module GitWrapper
|
5
|
-
class Error < StandardError; end
|
6
|
-
|
7
|
-
STATI_MATCHERS = {
|
8
|
-
modified_rx: /^ M (.*)/,
|
9
|
-
untracked_rx: /^\?\? (.*)/,
|
10
|
-
staged_rx: /^M (.*)/,
|
11
|
-
added_rx: /^A (.*)/
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
def self.command(cmd, opts = [])
|
15
|
-
gw = new
|
16
|
-
gw.call(cmd, opts)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.command_lines(cmd, opts = [])
|
20
|
-
result = command(cmd, opts)
|
21
|
-
lines = result.split("\n")
|
22
|
-
lines.each(&:strip!)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.branch_names
|
26
|
-
# NOTE: Regex matcher for cases as:
|
27
|
-
# remotes/origin/allow.... <- remote branch (remove 'remotes/origin')
|
28
|
-
# * allow.... <- * indicates current branch (remove '* ')
|
29
|
-
# allow <- local branch (do nothing)
|
30
|
-
regex = %r{(^remotes/.*/|\s|[*])}
|
31
|
-
all_branches.map do |line|
|
32
|
-
line = line.sub(regex, "")
|
33
|
-
line
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.current_branch
|
38
|
-
current_branch_line = all_branches.detect do |line|
|
39
|
-
line.match(/\*/)
|
40
|
-
end
|
41
|
-
current_branch_line.tr("*", " ").strip
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.all_branches
|
45
|
-
command_lines("branch", "-a")
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.create_branch(name)
|
49
|
-
command("checkout", ["-b", name])
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.status
|
53
|
-
g_status = command_lines("status", "-s")
|
54
|
-
return nil if g_status.empty?
|
55
|
-
|
56
|
-
{
|
57
|
-
modified: status_collect(g_status, STATI_MATCHERS[:modified_rx]),
|
58
|
-
untracked: status_collect(g_status, STATI_MATCHERS[:untracked_rx]),
|
59
|
-
added: status_collect(g_status, STATI_MATCHERS[:added_rx]),
|
60
|
-
staged: status_collect(g_status, STATI_MATCHERS[:staged_rx])
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.status_collect(status, regex)
|
65
|
-
chosen_stati = status.select { |e| e.match(regex) }
|
66
|
-
chosen_stati.map { |e| e.match(regex)[1] }
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.commit(message)
|
70
|
-
command("commit", ["-m", message])
|
71
|
-
end
|
72
|
-
|
73
|
-
def initialize
|
74
|
-
@system_git = "git"
|
75
|
-
end
|
76
|
-
|
77
|
-
def call(cmd, opts = [])
|
78
|
-
opts = prepare_opts(opts)
|
79
|
-
git_cmd = "#{@system_git} #{cmd} #{opts}"
|
80
|
-
`#{git_cmd}`.chomp.strip
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
# NOTE: Taken from ruby git gem
|
86
|
-
def escape(str = "")
|
87
|
-
str = str.to_s
|
88
|
-
return "'#{str.gsub("\'", '\'"\'"\'')}'" if /mingw|mswin/.match?(RUBY_PLATFORM)
|
89
|
-
|
90
|
-
# Keeping the old escape format for windows users
|
91
|
-
escaped = str.gsub("\'", "\'\\\'\'")
|
92
|
-
%("#{escaped}")
|
93
|
-
end
|
94
|
-
|
95
|
-
def prepare_opts(opts = [])
|
96
|
-
[opts].flatten.map { |s| escape(s) }.join(" ")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|