git_cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f63a2272d919b6734ab471ffc5a8ea087c7ddbf7e0f67087837e20338b3475f9
4
+ data.tar.gz: b4136958dd42cd0d47e3ea98eaf73a4cbc0e65841a1015c84da3c82c75618112
5
+ SHA512:
6
+ metadata.gz: 475d4c2702b87ef98f317302632489bb08873d0dfb9416e8cc503ab8cee67c8eccc08e5510e6b1a85513d4a47fd6b13368874a8ad24432535022ba1efd14d8ca
7
+ data.tar.gz: 121e66ffdf28f06ed960e2452852bb539e611121c1278750f59a77f4f72f7b7f5a9e63536c1761c49857c7bc01846f6f0e3f8fe116d4f20c8a662ef25105e7bb
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ tags
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at chrisliaw@antrapol.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git_cli.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Chris Liaw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # GitCli
2
+
3
+ This project is aimed to create the interfacing to GIT via the Command Line Interface (CLI). This is due to the CLI is always the latest version while library is lacking behind. Furthermore, library for Ruby or Java might not be coming in so soon, being later should be a better in keeping up the changes.
4
+
5
+ Hence the interfacing with the CLI seems the better way to do that.
6
+
7
+ This codes are tested using git version 2.25.1, Linux x86\_64
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'gvcs'
15
+ gem 'git_cli'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install gvcs
25
+ $ gem install git_cli
26
+
27
+ ## Usage
28
+
29
+ This gem is intended to be the provider for Gvcs generic API. It is used together with [Gvcs](https://github.com/chrisliaw/gvcs).
30
+
31
+ Example usage:
32
+
33
+ ```ruby
34
+ require 'gvcs'
35
+ # require git_cli after gvcs because git_cli will initialize the gvcs classes with appropriate methods
36
+ require 'git_cli'
37
+
38
+ # Loading the provider.
39
+ # in this case is git_cli
40
+ vcs = Gvcs::Vcs.new
41
+ vcs.init(path) # init workspace at the given path
42
+
43
+ @ws = Gvcs::Workspace.new(vcs, path)
44
+ # @ws now can invoke all supported git operations
45
+
46
+ ```
47
+
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chrisliaw/git_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/chrisliaw/git_cli/blob/master/CODE_OF_CONDUCT.md).
58
+
59
+
60
+ ## Code of Conduct
61
+
62
+ Everyone interacting in the GitCli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/chrisliaw/git_cli/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/git_cli/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "git_cli"
5
+ spec.version = GitCli::VERSION
6
+ spec.authors = ["Chris Liaw"]
7
+ spec.email = ["chrisliaw@antrapol.com"]
8
+
9
+ spec.summary = %q{GIT command line interface}
10
+ spec.description = %q{Interface to GIT via command line interface instead of some sor of library}
11
+ spec.homepage = "https://github.com/chrisliaw/git_cli"
12
+ spec.license = "GPL-3.0"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ #spec.metadata["homepage_uri"] = spec.homepage
18
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "tlogger", "~> 0.21"
31
+ spec.add_dependency "toolrack", "~> 0.4.0"
32
+ spec.add_dependency "version_utils", "~> 0.1.0"
33
+ end
@@ -0,0 +1,220 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "git_cli/version"
18
+
19
+ require 'toolrack'
20
+ require 'version_utils'
21
+
22
+ require_relative "git_cli/git_core"
23
+ require_relative "git_cli/init"
24
+ require_relative "git_cli/clone"
25
+ require_relative "git_cli/add_commit"
26
+ require_relative "git_cli/delta"
27
+ require_relative "git_cli/push"
28
+ require_relative "git_cli/pull"
29
+ require_relative "git_cli/branch"
30
+ require_relative "git_cli/diff"
31
+ require_relative "git_cli/ignore"
32
+ require_relative "git_cli/log"
33
+ require_relative "git_cli/tags"
34
+ require_relative "git_cli/repos"
35
+ require_relative "git_cli/stash"
36
+
37
+
38
+ module GitCli
39
+ class Error < StandardError; end
40
+ # Your code goes here...
41
+
42
+ MIN_GIT_VERSION = "2.22"
43
+
44
+ module Common
45
+ include Antrapol::ToolRack::ConditionUtils
46
+ include Antrapol::ToolRack::ExceptionUtils
47
+
48
+ def os_exec(path, &block)
49
+ # redirect stderr to stdout
50
+ path = "#{path} 2>&1"
51
+ res = Antrapol::ToolRack::ProcessUtilsEngine.exec(path)
52
+ if block
53
+ # $?.exitstatus => error codes
54
+ # $?.success? => true / false
55
+ # $?.pid => child PID
56
+ block.call($?, res)
57
+ else
58
+ res.strip
59
+ end
60
+ end
61
+
62
+ def log_debug(str)
63
+ GitCli::Global.instance.logger.debug(str)
64
+ end
65
+
66
+ def log_error(str)
67
+ GitCli::Global.instance.logger.error(str)
68
+ end
69
+
70
+ def log_warn(str)
71
+ GitCli::Global.instance.logger.warn(str)
72
+ end
73
+ end # common operations
74
+
75
+ class Gvcs::Vcs
76
+ include GitCli::Common
77
+ include GitCli::GitCore
78
+ include GitCli::Init
79
+ include GitCli::Clone
80
+
81
+ def initialize
82
+ # version check
83
+ vst, tver = version
84
+ if vst
85
+ st = VersionUtils.new.compare(MIN_GIT_VERSION, tver)
86
+ if st == -1 # 1st val > 2nd val == current version is smaller than installed
87
+ log_warn("Min required version of GIT is #{MIN_GIT_VERSION}. System installed GIT is version #{tver}. The output might not be correct.")
88
+ end
89
+
90
+ log_debug "System GIT version is #{tver}. Min require version is #{MIN_GIT_VERSION}"
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ module WsCommon
97
+ def check_vcs
98
+ raise_if_empty(@vcs, "VCS must not be null", GitCliException)
99
+ raise_if_empty(@wsPath, "Workspace path must not be null", GitCliException)
100
+ end
101
+
102
+ def check_repos
103
+ raise_if_empty(@repos, "Repository must not be null", GitCliException)
104
+ end
105
+ end # WsCommon
106
+
107
+ class Gvcs::Workspace
108
+ include GitCli::Common
109
+ include WsCommon
110
+ include GitCli::AddCommit
111
+ include GitCli::Delta
112
+ include GitCli::Push
113
+ include GitCli::Pull
114
+ include GitCli::Branch
115
+ include GitCli::Diff
116
+ include GitCli::Ignore
117
+ include GitCli::Log
118
+ include GitCli::Tags
119
+ include GitCli::Repos
120
+ include GitCli::Stash
121
+
122
+ attr_accessor :repos
123
+ def initialize(vcs, path)
124
+
125
+ raise_if_empty(vcs , "VCS cannot be empty", GitCliException)
126
+ raise_if_empty(path, "Workspace path cannot be empty", GitCliException)
127
+
128
+ @vcs = vcs
129
+ @givenPath = path
130
+
131
+ @wsPath = File.expand_path(@givenPath)
132
+
133
+ @repos = []
134
+
135
+ end # initialize
136
+
137
+ def path
138
+ @wsPath
139
+ end
140
+
141
+ def vcs
142
+ @vcs
143
+ end
144
+
145
+ def add_repos(repos)
146
+ @repos << repos if not repos.nil?
147
+ end # add_repos
148
+
149
+ def check_repos
150
+ raise_if_empty(@repos, "Repositories should not be empty", GitCliException)
151
+ end # check_repos
152
+
153
+ def is_repos_exist?(name)
154
+ found = false
155
+ @repos.each do |re|
156
+ if re.name == name
157
+ found = true
158
+ break
159
+ end
160
+ end
161
+ found
162
+ end # is_repos_exist?
163
+
164
+ def is_workspace?
165
+ st, res = status
166
+ st
167
+ end
168
+
169
+ def workspace_root
170
+
171
+ if (@wsRoot.nil? or (@wsRoot[0] == false))
172
+
173
+ check_vcs
174
+
175
+ cmd = []
176
+ cmd << "cd"
177
+ cmd << @wsPath
178
+ cmd << "&&"
179
+ cmd << @vcs.exe_path
180
+ cmd << "rev-parse --show-toplevel"
181
+
182
+ cmdln = cmd.join(" ")
183
+ log_debug "Workspace root: #{cmdln}"
184
+ res = os_exec(cmdln) do |st, res|
185
+
186
+ if st.success?
187
+ @wsRoot = [true, res]
188
+ else
189
+ @wsRoot = [false, res]
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+ @wsRoot
196
+
197
+ end # workspace_root
198
+
199
+ end # Gvcs::Workspace
200
+
201
+
202
+ class Gvcs::Repository
203
+
204
+ attr_reader :sslVerify
205
+ attr_reader :name, :url
206
+ #attr_accessor :branches
207
+ def initialize(name, url) #, branches = [])
208
+ @name = name
209
+ @url = url
210
+ #@branches = branches
211
+ @sslVerify = true
212
+ end
213
+
214
+ def ssl_verify(bool)
215
+ @sslVerify = bool
216
+ end
217
+
218
+ end # repository
219
+
220
+ end