commit 0.7.0
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 +7 -0
- data/.rubocop.yml +58 -0
- data/CHANGELOG.md +25 -0
- data/README.md +98 -0
- data/Rakefile +40 -0
- data/commit.gemspec +41 -0
- data/exe/commit +5 -0
- data/lib/commit/cli.rb +20 -0
- data/lib/commit/git_commit.rb +109 -0
- data/lib/commit/helper.rb +99 -0
- data/lib/commit/options.rb +58 -0
- data/lib/commit/version.rb +3 -0
- data/lib/commit.rb +21 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 525332be2b7dd147395cdc951b849ea9bd41c96824c3140264de5bb7f531d0c0
|
4
|
+
data.tar.gz: '019c86addf56a91823cb337bc3438c9c6e8a002d453ed2383a429fcc77432df1'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b1e74b61b336af2aa2793fd0749062f2ccdc434841dd2022ad78c6311527062f48a82f2ae16e2e238670dd18194ff01e84702c38ab0c5c66948fcf1515ad594
|
7
|
+
data.tar.gz: 857d5edf90f4022dd4a71e66dcdfdabee3607edfe811e520b5a94f7fd8bbe3db5dd4bdd4f8e5993d0e1443f352d9908f6f5d86f9b5e452eea07fd0c8b7ba9ddd
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-md
|
3
|
+
- rubocop-performance
|
4
|
+
- rubocop-rake
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- binstub/**/*
|
9
|
+
- exe/**/*
|
10
|
+
- vendor/**/*
|
11
|
+
- Gemfile*
|
12
|
+
NewCops: enable
|
13
|
+
|
14
|
+
Gemspec/DeprecatedAttributeAssignment:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Gemspec/RequireMFA:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout/HashAlignment:
|
21
|
+
EnforcedColonStyle: table
|
22
|
+
EnforcedHashRocketStyle: table
|
23
|
+
|
24
|
+
Layout/LineLength:
|
25
|
+
Max: 150
|
26
|
+
|
27
|
+
Metrics/AbcSize:
|
28
|
+
Max: 35
|
29
|
+
|
30
|
+
Metrics/BlockLength:
|
31
|
+
Exclude:
|
32
|
+
- commit.gemspec
|
33
|
+
Max: 30
|
34
|
+
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Max: 15
|
37
|
+
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Max: 40
|
40
|
+
|
41
|
+
Metrics/ModuleLength:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Metrics/PerceivedComplexity:
|
45
|
+
Max: 15
|
46
|
+
|
47
|
+
Naming/FileName:
|
48
|
+
Exclude:
|
49
|
+
- Rakefile
|
50
|
+
|
51
|
+
Style/Documentation:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/FrozenStringLiteralComment:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/TrailingCommaInHashLiteral:
|
58
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 0.7.0 / 2025-06-14
|
4
|
+
|
5
|
+
* Options are processed once again; this broke in v0.6.0.
|
6
|
+
* Now works from any subdirectory of a git repository.
|
7
|
+
* Now verifies that the command is run from within a git repository.
|
8
|
+
|
9
|
+
|
10
|
+
## 0.6.0 / 2025-06-09
|
11
|
+
|
12
|
+
* Filename with embedded single quotes are now processed correctly.
|
13
|
+
* The `.gitignore` documentation states that filenames with embedded spaces need to escape the spaces with backslashes.
|
14
|
+
It fails to mention that `[]` characters must also be escaped.
|
15
|
+
This version escapes all three characters.
|
16
|
+
|
17
|
+
|
18
|
+
## 0.5.0
|
19
|
+
|
20
|
+
* First version of this code as a Ruby gem.
|
21
|
+
|
22
|
+
|
23
|
+
## 0.4.0
|
24
|
+
|
25
|
+
* Last version of this code as a standalone script.
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# `Commit` [](https://badge.fury.io/rb/commit)
|
2
|
+
|
3
|
+
Runs git commit without prompting for a message.
|
4
|
+
Files larger than 2 GB are added to .gitignore instead of being committed.
|
5
|
+
|
6
|
+
This gem is further described in [A Streamlined Git Commit](https://mslinn.com/git/1050-commit.html).
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
1) [Install the `rugged` gem.](https://mslinn.com/git/4400-rugged.html)
|
12
|
+
2) Type:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem install commit
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```shell
|
22
|
+
$ commit [options] [file...]
|
23
|
+
```
|
24
|
+
|
25
|
+
Where options are:
|
26
|
+
|
27
|
+
- `-a "tag message"`
|
28
|
+
- `-m "commit message"`
|
29
|
+
- `-v 0 # Minimum verbosity`
|
30
|
+
- `-v 1 # Default verbosity`
|
31
|
+
- `-v 2 # Maximum verbosity`
|
32
|
+
|
33
|
+
|
34
|
+
### Examples
|
35
|
+
|
36
|
+
```shell
|
37
|
+
$ commit # The default commit message is just a single dash (-)
|
38
|
+
$ commit -v 0
|
39
|
+
$ commit -m "This is a commit message"
|
40
|
+
$ commit -v 0 -m "This is a commit message"
|
41
|
+
$ commit -a 0.1.2
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out this git repository, install dependencies by typing:
|
48
|
+
|
49
|
+
```shell
|
50
|
+
$ bin/setup
|
51
|
+
```
|
52
|
+
|
53
|
+
You should do the above before running Visual Studio Code.
|
54
|
+
|
55
|
+
|
56
|
+
### Run the Tests
|
57
|
+
|
58
|
+
```shell
|
59
|
+
$ bundle exec rake test
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
### Interactive Session
|
64
|
+
|
65
|
+
The following will allow you to experiment:
|
66
|
+
|
67
|
+
```shell
|
68
|
+
$ bin/console
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
### Local Installation
|
73
|
+
|
74
|
+
To install this gem onto your local machine, type:
|
75
|
+
|
76
|
+
```shell
|
77
|
+
$ bundle exec rake install
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
### To Release A New Version
|
82
|
+
|
83
|
+
To create a git tag for the new version, push git commits and tags,
|
84
|
+
and push the new version of the gem to https://rubygems.org, type:
|
85
|
+
|
86
|
+
```shell
|
87
|
+
$ bundle exec rake release
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome at https://github.com/mslinn/commit.
|
94
|
+
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
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
|
+
desc 'Bump patch version'
|
11
|
+
task :patch do
|
12
|
+
system 'gem bump --tag'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Bump minor version'
|
16
|
+
task :minor do
|
17
|
+
system 'gem bump --version minor --tag'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Bump major version'
|
21
|
+
task :major do
|
22
|
+
system 'gem bump --version major --tag'
|
23
|
+
end
|
24
|
+
|
25
|
+
task publish: [:build] do
|
26
|
+
$VERBOSE = nil
|
27
|
+
load 'commit/version.rb'
|
28
|
+
system "gem push pkg/commit-#{Commit::VERSION}.gem"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Bump patch version, create git tag, build the gem and release to geminabox (default)'
|
32
|
+
task release_patch: %i[test patch publish]
|
33
|
+
|
34
|
+
desc 'Bump minor version, create git tag, build the gem and release to geminabox'
|
35
|
+
task release_minor: %i[test minor publish]
|
36
|
+
|
37
|
+
desc 'Bump major version, create git tag, build the gem and release to geminabox'
|
38
|
+
task release_major: %i[test major publish]
|
39
|
+
|
40
|
+
task default: :test
|
data/commit.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'lib/commit/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
host = 'https://github.com/mslinn/commit'
|
5
|
+
|
6
|
+
spec.authors = ['Mike Slinn']
|
7
|
+
spec.bindir = 'exe'
|
8
|
+
spec.executables = ['commit']
|
9
|
+
spec.description = <<~END_DESC
|
10
|
+
Performs the following:
|
11
|
+
1) git add
|
12
|
+
2) git commit
|
13
|
+
3) git push
|
14
|
+
Works with Git LFS
|
15
|
+
END_DESC
|
16
|
+
spec.email = ['mslinn@mslinn.com']
|
17
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib}/**/*', '*.gemspec', '*.md']
|
18
|
+
spec.homepage = 'https://github.com/mslinn/commit'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
spec.metadata = {
|
21
|
+
'allowed_push_host' => 'https://rubygems.org',
|
22
|
+
'bug_tracker_uri' => "#{host}/issues",
|
23
|
+
'changelog_uri' => "#{host}/CHANGELOG.md",
|
24
|
+
'homepage_uri' => spec.homepage,
|
25
|
+
'source_code_uri' => host,
|
26
|
+
}
|
27
|
+
spec.name = 'commit'
|
28
|
+
spec.post_install_message = <<~END_MESSAGE
|
29
|
+
|
30
|
+
Thanks for installing #{spec.name}!
|
31
|
+
|
32
|
+
END_MESSAGE
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
spec.required_ruby_version = '>= 3.1.0'
|
35
|
+
spec.summary = 'Write summary of what the gem is for'
|
36
|
+
spec.version = Commit::VERSION
|
37
|
+
spec.add_dependency 'activesupport'
|
38
|
+
spec.add_dependency 'colorator'
|
39
|
+
spec.add_dependency 'optparse'
|
40
|
+
spec.add_dependency 'rugged'
|
41
|
+
end
|
data/exe/commit
ADDED
data/lib/commit/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'colorator'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
def require_subdirectory(dir)
|
6
|
+
Dir[File.join(dir, '*.rb')].each do |file|
|
7
|
+
require file unless file == __FILE__
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require_subdirectory File.realpath(__dir__) # Require all Ruby files in 'lib/', except this file
|
12
|
+
Pathname(__dir__).children.select(&:directory?).each do |directory|
|
13
|
+
require_subdirectory directory.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
module Commit
|
17
|
+
def self.main
|
18
|
+
GitCommit.new.main
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/numeric/conversions'
|
3
|
+
require 'colorator'
|
4
|
+
require 'optparse'
|
5
|
+
require 'rugged'
|
6
|
+
|
7
|
+
KB = 1024
|
8
|
+
MB = KB * KB
|
9
|
+
GB = KB * MB
|
10
|
+
# File size limits for git commits depend on the type of your GitHub account:
|
11
|
+
GITHUB_FREE = 100 * MB
|
12
|
+
GITHUB_PRO = 2 * GB
|
13
|
+
GITHUB_TEAM = 4 * GB
|
14
|
+
GITHUB_ENTERPRISE_CLOUD = 5 * GB
|
15
|
+
|
16
|
+
GIT_LFS_ENABLED = false
|
17
|
+
|
18
|
+
MAX_SIZE = GIT_LFS_ENABLED ? GITHUB_FREE : 100 * MB # Adjust this to suit your GitHub account
|
19
|
+
|
20
|
+
# Originally written in bash by Mike Slinn 2005-09-05
|
21
|
+
# Converted to Ruby and added MAX_SIZE 2024-12-11
|
22
|
+
# See https://docs.github.com/en/repositories/working-with-files/managing-large-files/configuring-git-large-file-storage
|
23
|
+
# See https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-large-files-on-github
|
24
|
+
class GitCommit
|
25
|
+
ActiveSupport::NumberHelper.alias_method :to_human, :number_to_human_size
|
26
|
+
|
27
|
+
def initialize(default_branch: 'master')
|
28
|
+
@branch = default_branch
|
29
|
+
@commit_size = 0
|
30
|
+
@gitignore_dirty = false
|
31
|
+
@nh = ActiveSupport::NumberHelper
|
32
|
+
end
|
33
|
+
|
34
|
+
def commit_push(msg = '-')
|
35
|
+
puts msg.yellow if msg
|
36
|
+
msg = @options[:commit_message] if @options[:commit_message]
|
37
|
+
discover_branch
|
38
|
+
|
39
|
+
puts "Committing with message '#{msg}'".green unless @options[:verbosity].zero?
|
40
|
+
run("git commit -m '#{msg}' 2>&1 | sed -e '/^X11/d' -e '/^Warning:/d'", verbose: @options[:verbosity] >= 2)
|
41
|
+
# @repo.push 'origin', ['refs/heads/master'] # Needs a callback to handle authentication
|
42
|
+
puts "Pushing to origin #{@branch}".green unless @options[:verbosity].zero?
|
43
|
+
run("git push origin #{@branch} --tags 3>&1 1>&2 2>&3 | sed -e '/^X11/d' -e '/^Warning:/d'", verbose: @options[:verbosity] >= 2)
|
44
|
+
@change_count = 0
|
45
|
+
@commit_size = 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def discover_branch
|
49
|
+
if @repo.branches.entries.empty?
|
50
|
+
# puts "\nYour git repository is empty. Please add at least one file before committing.".red
|
51
|
+
# exit 4
|
52
|
+
run "git branch -M #{@branch}"
|
53
|
+
else
|
54
|
+
@branch = @repo.head.name.sub(%r{^refs/heads/}, '')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def git_project?
|
59
|
+
run 'git rev-parse 2> /dev/null', verbose: false
|
60
|
+
end
|
61
|
+
|
62
|
+
def large_files
|
63
|
+
large = []
|
64
|
+
@repo.status do |path, flags|
|
65
|
+
puts "#{path} #{flags}" if @options[:verbosity].positive?
|
66
|
+
if File(path).dir?
|
67
|
+
scan_dir path
|
68
|
+
elsif large_file?(filename)
|
69
|
+
large << path.gsub(' ', '\ ').gsub('[', '\[').gsub(']', '\]')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
large
|
73
|
+
end
|
74
|
+
|
75
|
+
def main
|
76
|
+
@options = parse_options
|
77
|
+
repo_dir = ARGV.empty? ? Dir.pwd : ARGV[0]
|
78
|
+
Dir.chdir(repo_dir) unless ARGV.empty?
|
79
|
+
if git_project?
|
80
|
+
process_tag # Exits if a tag was created
|
81
|
+
@repo = Rugged::Repository.new repo_dir
|
82
|
+
recursive_add
|
83
|
+
commit_push if @commit_size.positive?
|
84
|
+
else
|
85
|
+
puts "Error: '#{repo_dir}' does not contain a git project".red
|
86
|
+
exit 3
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_tag
|
91
|
+
tag = @options[:tag]
|
92
|
+
return unless tag
|
93
|
+
|
94
|
+
run("git tag -a #{tag} -m 'v#{tag}'", verbose: @options[:verbosity] >= 2)
|
95
|
+
run('git push origin --tags', verbose: @options[:verbosity] >= 2)
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
|
99
|
+
# @param command can be a String or an Array of String
|
100
|
+
def run(command, verbose: true, do_not_execute: false)
|
101
|
+
if command.instance_of?(Array)
|
102
|
+
puts command.join(' ') if verbose
|
103
|
+
Kernel.system(*command) unless do_not_execute
|
104
|
+
else
|
105
|
+
puts command if verbose
|
106
|
+
`#{command}`.chomp unless do_not_execute
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class GitCommit
|
2
|
+
# Needs absolute path or the path relative to the current directory, not just the name of the directory
|
3
|
+
def add_recursively(name)
|
4
|
+
Dir.entries(name).each do |entry|
|
5
|
+
path = "#{name}/#{entry}"
|
6
|
+
if File.directory(entry)
|
7
|
+
scan_directory path
|
8
|
+
else
|
9
|
+
file_add path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Handles single quotes, spaces and square braces in the given string
|
15
|
+
def escape(string)
|
16
|
+
string.gsub("'", "\\\\'")
|
17
|
+
.gsub(' ', '\\ ')
|
18
|
+
.gsub('[', '\\[')
|
19
|
+
.gsub(']', '\\]')
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param filename [String] Must be a path relative to the git root
|
23
|
+
def file_add(filename)
|
24
|
+
file_size = File.exist?(filename) ? File.size(filename) : 0
|
25
|
+
if large_file?(filename)
|
26
|
+
msg = <<~MESSAGE
|
27
|
+
Not adding '#{filename}' because the git file size limit is #{@nh.to_human MAX_SIZE},
|
28
|
+
however the file is #{@nh.to_human file_size}.
|
29
|
+
The file will be added to .gitignore.
|
30
|
+
MESSAGE
|
31
|
+
puts msg.yellow unless @options[:verbosity].zero?
|
32
|
+
|
33
|
+
newline = needs_newline('.gitignore') ? "\n" : ''
|
34
|
+
File.write('.gitignore', "#{newline}#{filename}\n", mode: 'a')
|
35
|
+
@gitignore_dirty = true
|
36
|
+
elsif filename == '.gitignore'
|
37
|
+
@gitignore_dirty = true
|
38
|
+
else
|
39
|
+
commit_push('A portion of the files to be committed is being pushed now because they are large.') if @commit_size + file_size >= MAX_SIZE / 2.0
|
40
|
+
puts "Adding '#{escape filename}'".green unless @options[:verbosity].zero?
|
41
|
+
run ['git', 'add', escape(filename)], verbose: @options[:verbosity] >= 2
|
42
|
+
end
|
43
|
+
@change_count += 1
|
44
|
+
@commit_size += file_size
|
45
|
+
end
|
46
|
+
|
47
|
+
# Assumes .gitignore is never large
|
48
|
+
def large_file?(filename)
|
49
|
+
File.size(filename) > MAX_SIZE if File.exist?(filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
def needs_newline(filename)
|
53
|
+
return false unless File.exist? filename
|
54
|
+
|
55
|
+
file_contents = File.read filename
|
56
|
+
file_contents.nil? || file_contents.empty? || !file_contents.end_with?("\n")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Exclude big files, git add all others
|
60
|
+
# @repo.status returns the following values for flags:
|
61
|
+
# - +:index_new+: the file is new in the index
|
62
|
+
# - +:index_modified+: the file has been modified in the index
|
63
|
+
# - +:index_deleted+: the file has been deleted from the index
|
64
|
+
# - +:worktree_new+: the file is new in the working directory
|
65
|
+
# - +:worktree_modified+: the file has been modified in the working directory
|
66
|
+
# - +:worktree_deleted+: the file has been deleted from the working directory
|
67
|
+
def recursive_add
|
68
|
+
@change_count = 0
|
69
|
+
@repo.status do |path, flags|
|
70
|
+
next if flags.include? :ignored
|
71
|
+
|
72
|
+
if File.directory? path
|
73
|
+
scan_directory path
|
74
|
+
else
|
75
|
+
file_add path
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if @gitignore_dirty
|
79
|
+
puts 'Changing .gitignore'.green unless @options[:verbosity].zero?
|
80
|
+
run 'git add .gitignore', verbose: @options[:verbosity] >= 2
|
81
|
+
@change_count += 1
|
82
|
+
end
|
83
|
+
return unless @change_count.zero?
|
84
|
+
|
85
|
+
puts 'No changes were detected to this git repository.'.green if @options[:verbosity].positive?
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
def scan_directory(path)
|
90
|
+
Dir.children(path) do |name|
|
91
|
+
child_path = "#{path}/#{name}"
|
92
|
+
if File.directory? child_path
|
93
|
+
scan_directory child_path
|
94
|
+
else
|
95
|
+
file_add child_path
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'colorator'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
class GitCommit
|
5
|
+
def help(msg = nil)
|
6
|
+
printf "Error: #{msg}\n\n".yellow unless msg.nil?
|
7
|
+
msg = <<~HELP
|
8
|
+
commit v#{Commit::VERSION}
|
9
|
+
|
10
|
+
Runs git commit without prompting for a message.
|
11
|
+
Files larger than #{@nh.to_human MAX_SIZE} are added to .gitignore instead of being committed.
|
12
|
+
|
13
|
+
Usage: commit [options]
|
14
|
+
Where options are:
|
15
|
+
-a "tag message"
|
16
|
+
-m "commit message"
|
17
|
+
-v 0 # Minimum verbosity
|
18
|
+
-v 1 # Default verbosity
|
19
|
+
-v 2 # Maximum verbosity
|
20
|
+
|
21
|
+
Examples:
|
22
|
+
commit # The default commit message is just a single dash (-)
|
23
|
+
commit -v 0
|
24
|
+
commit -m "This is a commit message"
|
25
|
+
commit -v 0 -m "This is a commit message"
|
26
|
+
commit -a 0.1.2
|
27
|
+
|
28
|
+
This gem is further described in https://mslinn.com/git/1050-commit.html
|
29
|
+
HELP
|
30
|
+
puts msg.yellow
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_options
|
35
|
+
options = { message: '-', verbosity: 1 }
|
36
|
+
OptionParser.new do |parser|
|
37
|
+
parser.program_name = File.basename __FILE__
|
38
|
+
@parser = parser
|
39
|
+
|
40
|
+
parser.on('-a', '--tag TAG_MESSAGE', 'Specify tag message')
|
41
|
+
parser.on('-m', '--message COMMIT_MESSAGE', 'Specify commit message')
|
42
|
+
parser.on('-v', '--verbosity VERBOSITY', Integer, 'Verbosity (0..2)')
|
43
|
+
|
44
|
+
parser.on_tail('-h', '--help', 'Show this message') do
|
45
|
+
help
|
46
|
+
end
|
47
|
+
end.order!(into: options)
|
48
|
+
help "Invalid verbosity value (#{options[:verbosity]})." if options[:verbosity].negative? || options[:verbosity] > 2
|
49
|
+
if ARGV.length > 1
|
50
|
+
help <<~END_MSG
|
51
|
+
Incorrect syntax.
|
52
|
+
After removing the options, the remaining command line was:
|
53
|
+
#{ARGV.join ' '}
|
54
|
+
END_MSG
|
55
|
+
end
|
56
|
+
options
|
57
|
+
end
|
58
|
+
end
|
data/lib/commit.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'colorator'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
def require_subdirectory(dir)
|
6
|
+
Dir[File.join(dir, '*.rb')].each do |file|
|
7
|
+
require file unless file == __FILE__
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
git_dir = `git rev-parse --show-toplevel`.chomp
|
12
|
+
if git_dir.empty?
|
13
|
+
puts 'This script must be run from within a git repository.'.red
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
Dir.chdir(git_dir) # Change to the root of the git repository
|
17
|
+
|
18
|
+
require_subdirectory File.realpath(__dir__) # Require all Ruby files in 'lib/', except this file
|
19
|
+
Pathname(__dir__).children.select(&:directory?).each do |directory|
|
20
|
+
require_subdirectory directory.to_s
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Slinn
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: activesupport
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: colorator
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: optparse
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rugged
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
description: |
|
69
|
+
Performs the following:
|
70
|
+
1) git add
|
71
|
+
2) git commit
|
72
|
+
3) git push
|
73
|
+
Works with Git LFS
|
74
|
+
email:
|
75
|
+
- mslinn@mslinn.com
|
76
|
+
executables:
|
77
|
+
- commit
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- ".rubocop.yml"
|
82
|
+
- CHANGELOG.md
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- commit.gemspec
|
86
|
+
- exe/commit
|
87
|
+
- lib/commit.rb
|
88
|
+
- lib/commit/cli.rb
|
89
|
+
- lib/commit/git_commit.rb
|
90
|
+
- lib/commit/helper.rb
|
91
|
+
- lib/commit/options.rb
|
92
|
+
- lib/commit/version.rb
|
93
|
+
homepage: https://github.com/mslinn/commit
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
allowed_push_host: https://rubygems.org
|
98
|
+
bug_tracker_uri: https://github.com/mslinn/commit/issues
|
99
|
+
changelog_uri: https://github.com/mslinn/commit/CHANGELOG.md
|
100
|
+
homepage_uri: https://github.com/mslinn/commit
|
101
|
+
source_code_uri: https://github.com/mslinn/commit
|
102
|
+
post_install_message: |2+
|
103
|
+
|
104
|
+
Thanks for installing commit!
|
105
|
+
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 3.1.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.6.9
|
121
|
+
specification_version: 4
|
122
|
+
summary: Write summary of what the gem is for
|
123
|
+
test_files: []
|
124
|
+
...
|