git-dust 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/git-dust +4 -0
- data/git-dust.gemspec +26 -0
- data/lib/git/dust.rb +103 -0
- data/spec/git/dust_spec.rb +104 -0
- data/spec/spec_helper.rb +12 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7fcf266a880a58f3dcb6c42871e667e0afb6593
|
4
|
+
data.tar.gz: 8c28817a0858fbcb1828f8b8d6ff358d9d6aedb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27ee9eb62b8462d09e61f89a99021ff49b17f3b97344ac7b962395c8b18078d04b41bde2ce5886226ebeb14eb57427c10e414bfe88a0aede6d256468dcf8349e
|
7
|
+
data.tar.gz: c736a53616c8a45100197f9ea5d90c6bff08c5bdfad14eea1531e3820244d31f50ec699d3d04ecbb45892a6e6d20e2357da15ba6671aa2af2ffe2e213e393811
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in git-dust.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "coveralls", require: false
|
8
|
+
# test needs restoring environments feature.
|
9
|
+
gem "git", require: false, github: "nishidayuya/ruby-git", ref: "e803dd65b7a851431835f72052e09e445a80e532"
|
10
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch("Gemfile")
|
3
|
+
watch(/\A.+\.gemspec\z/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, all_after_pass: true, all_on_start: true do
|
7
|
+
watch(%r{\Alib/(.+)\.rb\z}) { |m|
|
8
|
+
"spec/#{m[1]}_spec.rb"
|
9
|
+
}
|
10
|
+
watch("spec/spec_helper.rb") {
|
11
|
+
"spec"
|
12
|
+
}
|
13
|
+
watch(%r{\Aspec/.+_spec\.rb\z})
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuya.Nishida.
|
2
|
+
|
3
|
+
X11 License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# git dust
|
2
|
+
|
3
|
+
A Git sub command for Dust Commits Workflow.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/nishidayuya/git-dust.svg?branch=master)](https://travis-ci.org/nishidayuya/git-dust)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Depenedencies:
|
10
|
+
* git
|
11
|
+
* Ruby
|
12
|
+
|
13
|
+
Install standalone version:
|
14
|
+
```sh
|
15
|
+
$ curl https://raw.githubusercontent.com/nishidayuya/git-dust/master/lib/git/dust.rb > path-environment-directory/git-dust
|
16
|
+
$ chmod a+x path-environment-directory/git-dust
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To create many dust commits and squash them:
|
22
|
+
```sh
|
23
|
+
$ git add foo.txt
|
24
|
+
$ git dust commit
|
25
|
+
<commit foo.txt with commit message "git dust commit.">
|
26
|
+
$ git dust commit -a
|
27
|
+
<commit modified files with commit message "git dust commit.">
|
28
|
+
...
|
29
|
+
$ git dust fix
|
30
|
+
<squash dust commits and open editor to write commit message>
|
31
|
+
```
|
32
|
+
|
33
|
+
## News
|
34
|
+
|
35
|
+
* 0.0.0: 2014-07-12 first release.
|
36
|
+
* "git dust commit" and "git dust fix".
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/git-dust
ADDED
data/git-dust.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.join(__dir__, "lib")
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git-dust"
|
8
|
+
spec.version = "0.0.0"
|
9
|
+
spec.authors = ["Yuya.Nishida."]
|
10
|
+
spec.email = ["yuya@j96.org"]
|
11
|
+
spec.summary = "A Git sub command for Dust Commits Workflow."
|
12
|
+
spec.homepage = "https://github.com/nishidayuya/git-dust"
|
13
|
+
spec.license = "X11"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "guard-bundler"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
spec.add_development_dependency "pry-byebug"
|
26
|
+
end
|
data/lib/git/dust.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
# compatibility
|
7
|
+
if !Pathname.public_method_defined?(:write)
|
8
|
+
class Pathname
|
9
|
+
def write(*args)
|
10
|
+
open("w") do |f|
|
11
|
+
f.write(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Git
|
18
|
+
end
|
19
|
+
|
20
|
+
class Git::Dust
|
21
|
+
def self.help(args = [])
|
22
|
+
STDERR.puts(<<EOS)
|
23
|
+
#{File.basename($0)} <command> [<args>]
|
24
|
+
|
25
|
+
git dust commands are:
|
26
|
+
* commit
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.run(command_and_args)
|
31
|
+
command = command_and_args.first || "help"
|
32
|
+
command_symbol = command.gsub("-", "_").to_sym
|
33
|
+
args = command_and_args[1 .. -1]
|
34
|
+
defined_commands = public_methods(false) - %i(allocate new superclass run)
|
35
|
+
if defined_commands.include?(command_symbol)
|
36
|
+
send(command_symbol, args)
|
37
|
+
else
|
38
|
+
STDERR.puts("sub command not found: sub_command=<#{command}>")
|
39
|
+
STDERR.puts
|
40
|
+
help
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.commit(args)
|
46
|
+
run_command(*%w(git commit -m), COMMIT_MESSAGE, *args)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.fix(args)
|
50
|
+
base_sha1 = find_non_dust_commit
|
51
|
+
saved_editor_environment = ENV["GIT_SEQUENCE_EDITOR"]
|
52
|
+
begin
|
53
|
+
ENV["GIT_SEQUENCE_EDITOR"] = "git dust edit-rebase-commit-list"
|
54
|
+
run_command(*%w(git rebase -i), base_sha1)
|
55
|
+
ensure
|
56
|
+
ENV["GIT_SEQUENCE_EDITOR"] = saved_editor_environment
|
57
|
+
end
|
58
|
+
run_command(*%w(git reset --soft HEAD^))
|
59
|
+
run_command("git commit --edit")
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.edit_rebase_commit_list(args)
|
63
|
+
output = []
|
64
|
+
rebase_todo_path = Pathname(args.first)
|
65
|
+
rebase_todo_path.open do |f|
|
66
|
+
lines = f.each_line
|
67
|
+
lines.each do |l| # write first commit
|
68
|
+
if !/\A\s*#/.match(l)
|
69
|
+
output << l
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
lines.each do |l| # change "pick" to "fixup"
|
74
|
+
output << l.sub(/\Apick/, "fixup")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
rebase_todo_path.write(output.join)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
COMMIT_MESSAGE = "git dust commit.".freeze
|
83
|
+
|
84
|
+
def self.run_command(*args)
|
85
|
+
if !system(*args)
|
86
|
+
raise "failed: args=<#{args.inspect}>"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.find_non_dust_commit
|
91
|
+
Open3.popen2("git log --format=oneline") do |stdin, stdout, wait_thread|
|
92
|
+
stdout.each_line.each do |line|
|
93
|
+
sha1, subject = line.chomp.split(" ", 2)
|
94
|
+
return sha1 if COMMIT_MESSAGE != subject
|
95
|
+
end
|
96
|
+
end
|
97
|
+
raise "non dust commit is not exist."
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if $0 == __FILE__
|
102
|
+
Git::Dust.run(ARGV)
|
103
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Git::Dust do
|
4
|
+
def chenv(environments = {})
|
5
|
+
if block_given?
|
6
|
+
saved = chenv(environments)
|
7
|
+
begin
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
chenv(saved)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
saved = {}
|
14
|
+
environments.each do |key, value|
|
15
|
+
key = key.to_s
|
16
|
+
saved[key] = ENV[key]
|
17
|
+
ENV[key] = value.to_s
|
18
|
+
end
|
19
|
+
return saved
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:tmp_path) {
|
24
|
+
Pathname(Dir.mktmpdir)
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:g) {
|
28
|
+
Git.init((tmp_path + "git_working_directory").to_s)
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:file1_path) {
|
32
|
+
Pathname(g.dir.path) + "a.txt"
|
33
|
+
}
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
g.config("user.name", "git-dust test user")
|
37
|
+
g.config("user.email", "anonymous@git-dust.example.org")
|
38
|
+
|
39
|
+
file1_path.write("1\n")
|
40
|
+
g.add(all: true)
|
41
|
+
g.commit("first import.")
|
42
|
+
|
43
|
+
# only staging
|
44
|
+
file1_path.write("2\n")
|
45
|
+
g.add(all: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
tmp_path.rmtree
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ".commit" do
|
53
|
+
describe "empty args" do
|
54
|
+
it "commit staging files with commit message" do
|
55
|
+
g.chdir do
|
56
|
+
expect do
|
57
|
+
Git::Dust.commit([])
|
58
|
+
end.to change {g.log.count}.by(1)
|
59
|
+
end
|
60
|
+
expect(g.log.first.message).to eq("git dust commit.")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".fix" do
|
66
|
+
describe "empty args" do
|
67
|
+
let(:git_editor_input_path) {
|
68
|
+
path = tmp_path + "editor_input"
|
69
|
+
path.write("nothing input.\n") # will be overridden
|
70
|
+
path
|
71
|
+
}
|
72
|
+
|
73
|
+
let(:git_editor_path) {
|
74
|
+
path = tmp_path + "editor"
|
75
|
+
path.write(<<EOS)
|
76
|
+
#! /bin/sh
|
77
|
+
|
78
|
+
file=$1
|
79
|
+
cat $file > #{git_editor_input_path}
|
80
|
+
echo "some commit message." > $file
|
81
|
+
EOS
|
82
|
+
path.chmod(0755)
|
83
|
+
path
|
84
|
+
}
|
85
|
+
|
86
|
+
it "squash dust commits" do
|
87
|
+
g.chdir do
|
88
|
+
Git::Dust.commit([])
|
89
|
+
file1_path.write("3\n")
|
90
|
+
g.add(all: true)
|
91
|
+
Git::Dust.commit([])
|
92
|
+
chenv(PATH: [BIN_PATH, ENV["PATH"]].join(":"),
|
93
|
+
RUBYLIB: [LIB_PATH, ENV["RUBYLIB"]].join(":"),
|
94
|
+
GIT_EDITOR: git_editor_path) do
|
95
|
+
expect do
|
96
|
+
Git::Dust.fix([])
|
97
|
+
end.to change {g.log.count}.from(3).to(2)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
expect(g.log.first.message).to eq("some commit message.")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-dust
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuya.Nishida.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- yuya@j96.org
|
100
|
+
executables:
|
101
|
+
- git-dust
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Guardfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/git-dust
|
113
|
+
- git-dust.gemspec
|
114
|
+
- lib/git/dust.rb
|
115
|
+
- spec/git/dust_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
homepage: https://github.com/nishidayuya/git-dust
|
118
|
+
licenses:
|
119
|
+
- X11
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A Git sub command for Dust Commits Workflow.
|
141
|
+
test_files:
|
142
|
+
- spec/git/dust_spec.rb
|
143
|
+
- spec/spec_helper.rb
|