git-gsub 0.0.6 → 0.0.11
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 +5 -5
- data/.travis.yml +1 -0
- data/CHANGELOG.md +21 -0
- data/README.md +6 -1
- data/git-gsub.gemspec +7 -4
- data/lib/git/gsub.rb +7 -4
- data/lib/git/gsub/version.rb +1 -1
- data/spec/git_gsub_spec.rb +96 -34
- metadata +19 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdbaa36daf4b1b651664f8e2c6249c926b7da18813a523e5acef6ba9110298ea
|
4
|
+
data.tar.gz: ab255f1a554458c5f4725714015630b154fc9483a278fc246ffce967b4175837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3808ba02a0ed1ad307f657e566fb1bb2b2bb94653097f091280af21dae04bd795a1da01062285cd66ea1435272bb8d2aa091c838db2a14f74fc46d8c0ddc1d67
|
7
|
+
data.tar.gz: 32254b23f90248771eb31fca3c440c532fd2fce80668baba104e06ad0a4c85fb53e49fb52a04fb57d77bb0d2443fb86e58ff1d42eed13af5d7e00700fe2cc803
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.0.11]
|
5
|
+
### Changed
|
6
|
+
- Support newer and safer activesupport ([#13](https://github.com/fujimura/git-gsub/pull/13))
|
7
|
+
- Add deprecation message on installation ([#13](https://github.com/fujimura/git-gsub/pull/13))
|
8
|
+
|
9
|
+
## [0.0.10]
|
10
|
+
### Changed
|
11
|
+
- Support activesupport >= 4 & < 6 ([#12](https://github.com/fujimura/git-gsub/pull/12)) Thanks @hanachin!
|
12
|
+
|
13
|
+
## [0.0.9]
|
14
|
+
### Fixed
|
15
|
+
- Make `--dry-run` works with `--rename`([#10](https://github.com/fujimura/git-gsub/pull/10))
|
16
|
+
|
17
|
+
## [0.0.8]
|
18
|
+
### Fixed
|
19
|
+
- Fix bug on passing file names to `Open3.capture3`[c05a05c](https://github.com/fujimura/git-gsub/commit/c05a05cd413d5a389c781b6649b42a46a825c4db)
|
20
|
+
|
21
|
+
## [0.0.7]
|
22
|
+
### Fixed
|
23
|
+
- Fix escaping @([#8](https://github.com/fujimura/git-gsub/pull/8)) Thanks @amatsuda!
|
24
|
+
|
4
25
|
## [0.0.6]
|
5
26
|
### Added
|
6
27
|
- Add option to substitute in camel/kebab/snake case
|
data/README.md
CHANGED
@@ -16,6 +16,8 @@ Usage: git gsub [options] FROM TO [PATHS]
|
|
16
16
|
|
17
17
|
## Example
|
18
18
|
|
19
|
+
### Normal substutution
|
20
|
+
|
19
21
|
To substitute `Git` with `Subversion`:
|
20
22
|
|
21
23
|
```
|
@@ -47,7 +49,8 @@ index c30f093..03b7c4c 100755
|
|
47
49
|
+Subversion::Gsub.run
|
48
50
|
```
|
49
51
|
|
50
|
-
|
52
|
+
### Case-converting substitution
|
53
|
+
|
51
54
|
To substitute `CommonLisp` with `VisualBasic` with case-awareness:
|
52
55
|
|
53
56
|
```
|
@@ -66,6 +69,8 @@ index 2185dbf..393dbc6 100644
|
|
66
69
|
+# VisualBasic visual_basic visual-basic
|
67
70
|
```
|
68
71
|
|
72
|
+
### Substitute and rename file
|
73
|
+
|
69
74
|
Substitute and rename file:
|
70
75
|
|
71
76
|
```
|
data/git-gsub.gemspec
CHANGED
@@ -3,23 +3,26 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'git/gsub/version'
|
5
5
|
|
6
|
+
GIT_GSUB_RUBY_IS_DEPRECATED = %q{git-gsub: Newer version is written in Go and Ruby implementation is deprecated. See https://github.com/fujimura/git-gsub}
|
7
|
+
|
6
8
|
Gem::Specification.new do |spec|
|
7
9
|
spec.name = "git-gsub"
|
8
10
|
spec.version = Git::Gsub::VERSION
|
9
11
|
spec.authors = ["Fujimura Daisuke"]
|
10
12
|
spec.email = ["me@fujimuradaisuke.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
+
spec.summary = GIT_GSUB_RUBY_IS_DEPRECATED
|
14
|
+
spec.description = GIT_GSUB_RUBY_IS_DEPRECATED
|
13
15
|
spec.homepage = "https://github.com/fujimura/git-gsub"
|
14
16
|
spec.license = "MIT"
|
17
|
+
spec.post_install_message = GIT_GSUB_RUBY_IS_DEPRECATED
|
15
18
|
|
16
19
|
spec.files = `git ls-files -z`.split("\x0")
|
17
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.add_dependency "activesupport", "
|
22
|
+
spec.add_dependency "activesupport", ">= 6.0.3.1"
|
20
23
|
spec.require_paths = ["lib"]
|
21
24
|
|
22
|
-
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "bundler"
|
23
26
|
spec.add_development_dependency "rake"
|
24
27
|
spec.add_development_dependency "rspec"
|
25
28
|
spec.add_development_dependency "pry"
|
data/lib/git/gsub.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support/inflector'
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'shellwords'
|
5
5
|
require 'English'
|
6
|
+
require "open3"
|
6
7
|
|
7
8
|
module Git
|
8
9
|
module Gsub
|
@@ -78,9 +79,9 @@ module Git
|
|
78
79
|
|
79
80
|
def run_commands(commands)
|
80
81
|
if options[:dry]
|
81
|
-
commands.each { |
|
82
|
+
commands.each { |args| puts Array(args).join(' ') }
|
82
83
|
else
|
83
|
-
commands.each { |
|
84
|
+
commands.each { |args| Open3.capture3(*args) }
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
@@ -103,11 +104,13 @@ module Git
|
|
103
104
|
|
104
105
|
def build_command(from, to, paths = [], _options = {})
|
105
106
|
from, to, *paths = [from, to, *paths].map { |s| Shellwords.escape s }
|
107
|
+
[from, to].each { |s| s.gsub! '@', '\@' }
|
106
108
|
|
107
|
-
target_files = `git grep -l #{from} #{paths.join ' '}`.each_line.map(&:chomp)
|
109
|
+
target_files = `git grep -l #{from} #{paths.join ' '}`.each_line.map(&:chomp)
|
108
110
|
return if target_files.empty?
|
109
111
|
|
110
|
-
|
112
|
+
|
113
|
+
['perl', '-pi', '-e', "s{#{from}}{#{to}}g", *target_files]
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
data/lib/git/gsub/version.rb
CHANGED
data/spec/git_gsub_spec.rb
CHANGED
@@ -3,13 +3,15 @@ require 'tmpdir'
|
|
3
3
|
require 'git/gsub'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.filter_run :focus => true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
end
|
10
|
+
|
6
11
|
describe 'git-gsub' do
|
7
|
-
def
|
12
|
+
def run_in_tmp_repo
|
8
13
|
Dir.mktmpdir do |dir|
|
9
14
|
Dir.chdir dir do
|
10
|
-
dirname = File.dirname(filename)
|
11
|
-
FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
|
12
|
-
File.open(filename, 'w') { |f| f << content }
|
13
15
|
`git init`
|
14
16
|
`git config --local user.email "you@example.com"`
|
15
17
|
`git config --local user.name "Your Name"`
|
@@ -20,63 +22,123 @@ describe 'git-gsub' do
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def commit_file(name, content)
|
26
|
+
FileUtils.mkdir_p(File.dirname(name))
|
27
|
+
File.write(name, content)
|
28
|
+
`git add .`
|
29
|
+
`git commit -m 'Add #{name}'`
|
30
|
+
end
|
31
|
+
|
32
|
+
let!(:git_gsub_path) {
|
33
|
+
if ENV['USE_RUBY']
|
34
|
+
File.expand_path("../../bin/git-gsub-ruby", __FILE__)
|
35
|
+
else
|
36
|
+
File.expand_path("../../bin/git-gsub", __FILE__)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
around do |example|
|
41
|
+
run_in_tmp_repo do
|
42
|
+
example.run
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
describe 'Substituting' do
|
47
|
+
it 'should substitute files' do
|
48
|
+
commit_file 'README.md', 'Git Subversion Bzr'
|
49
|
+
`#{git_gsub_path} Bzr Mercurial`
|
50
|
+
|
51
|
+
expect(File.read('README.md')).to eq 'Git Subversion Mercurial'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should substitute files with case conversion' do
|
55
|
+
commit_file 'README.md', 'GitGsub git_gsub git-gsub'
|
56
|
+
`#{git_gsub_path} GitGsub SvnGsub --camel --kebab --snake`
|
57
|
+
|
33
58
|
expect(File.read('README.md')).to eq 'SvnGsub svn_gsub svn-gsub'
|
34
59
|
end
|
35
|
-
end
|
36
60
|
|
37
|
-
|
38
|
-
|
39
|
-
|
61
|
+
it 'should escape well' do
|
62
|
+
commit_file 'README.md', %(<h1 class="foo">)
|
63
|
+
`#{git_gsub_path} '<h1 class="foo">' '<h1 class="bar">'`
|
64
|
+
|
40
65
|
expect(File.read('README.md')).to eq %(<h1 class="bar">)
|
41
66
|
end
|
42
67
|
|
43
|
-
|
44
|
-
|
45
|
-
|
68
|
+
it 'should substutute @' do
|
69
|
+
commit_file 'README.md', %(foo@example.com)
|
70
|
+
`#{git_gsub_path} @example bar@example`
|
71
|
+
|
72
|
+
expect(File.read('README.md')).to eq %(foobar@example.com)
|
46
73
|
end
|
47
74
|
|
48
|
-
|
49
|
-
|
50
|
-
|
75
|
+
it 'should substitute consequenting @' do
|
76
|
+
commit_file 'README.md', %(Hello this is @git)
|
77
|
+
`#{git_gsub_path} @git @@svn`
|
78
|
+
|
79
|
+
expect(File.read('README.md')).to eq %(Hello this is @@svn)
|
51
80
|
end
|
52
|
-
end
|
53
81
|
|
54
|
-
|
55
|
-
|
56
|
-
|
82
|
+
it %(should substitute " to ') do
|
83
|
+
commit_file 'README.md', %(Hello this is "git")
|
84
|
+
`#{git_gsub_path} '"git"' "'svn'"`
|
85
|
+
|
86
|
+
expect(File.read('README.md')).to eq %(Hello this is 'svn')
|
87
|
+
end
|
88
|
+
|
89
|
+
it %(should substitute ' to ") do
|
90
|
+
commit_file 'README.md', %(Hello this is 'git')
|
91
|
+
`#{git_gsub_path} "'git'" '"svn"'`
|
92
|
+
|
93
|
+
expect(File.read('README.md')).to eq %(Hello this is "svn")
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should substitute text including { and }'do
|
97
|
+
commit_file 'README.md', %({git{svn})
|
98
|
+
`#{git_gsub_path} {git{svn} {hg{svn}}`
|
99
|
+
|
100
|
+
expect(File.read('README.md')).to eq %({hg{svn}})
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should not create backup file' do
|
104
|
+
commit_file 'README.md', 'Git Subversion Bzr'
|
105
|
+
`#{git_gsub_path} Bzr Darcs`
|
106
|
+
|
57
107
|
expect(`ls`).to eql "README.md\n"
|
58
108
|
end
|
59
109
|
end
|
60
110
|
|
61
|
-
|
62
|
-
|
63
|
-
|
111
|
+
describe 'Renaming' do
|
112
|
+
it 'should rename with --rename' do
|
113
|
+
commit_file 'README-git_gsub.md', 'GitGsub git_gsub git-gsub'
|
114
|
+
`#{git_gsub_path} GitGsub SvnGsub --snake --rename`
|
115
|
+
|
64
116
|
expect(`ls`).to eql "README-svn_gsub.md\n"
|
65
117
|
expect(File.read('README-svn_gsub.md')).to eq 'SvnGsub svn_gsub git-gsub'
|
66
118
|
end
|
67
119
|
|
68
|
-
|
69
|
-
|
120
|
+
it 'should rename with --rename' do
|
121
|
+
commit_file 'lib/git.rb', 'puts "Git"'
|
122
|
+
`#{git_gsub_path} git svn --camel --rename`
|
123
|
+
|
70
124
|
expect(`ls lib`).to eql "svn.rb\n"
|
71
125
|
expect(File.read('lib/svn.rb')).to eq 'puts "Svn"'
|
72
126
|
end
|
73
|
-
end
|
74
127
|
|
75
|
-
|
76
|
-
|
128
|
+
it 'should do nothing if no file found' do
|
129
|
+
commit_file 'README-git_gsub.md', 'GitGsub git_gsub git-gsub'
|
130
|
+
|
77
131
|
expect {
|
78
|
-
|
132
|
+
`#{git_gsub_path} Atlanta Chicago --snake --rename`
|
79
133
|
}.not_to raise_error
|
80
134
|
end
|
81
135
|
end
|
136
|
+
|
137
|
+
it 'should output command with dry-run' do
|
138
|
+
commit_file 'README-git_gsub.md', 'GitGsub git_gsub git-gsub'
|
139
|
+
|
140
|
+
expect {
|
141
|
+
Git::Gsub.run %w[GitGsub SvnGsub --snake --rename --dry-run]
|
142
|
+
}.to output(/Svn/).to_stdout
|
143
|
+
end
|
82
144
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-gsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fujimura Daisuke
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.3.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.3.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: 'git-gsub: Newer version is written in Go and Ruby implementation is
|
84
|
+
deprecated. See https://github.com/fujimura/git-gsub'
|
84
85
|
email:
|
85
86
|
- me@fujimuradaisuke.com
|
86
87
|
executables:
|
@@ -104,7 +105,8 @@ homepage: https://github.com/fujimura/git-gsub
|
|
104
105
|
licenses:
|
105
106
|
- MIT
|
106
107
|
metadata: {}
|
107
|
-
post_install_message:
|
108
|
+
post_install_message: 'git-gsub: Newer version is written in Go and Ruby implementation
|
109
|
+
is deprecated. See https://github.com/fujimura/git-gsub'
|
108
110
|
rdoc_options: []
|
109
111
|
require_paths:
|
110
112
|
- lib
|
@@ -119,10 +121,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
121
|
- !ruby/object:Gem::Version
|
120
122
|
version: '0'
|
121
123
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
124
|
+
rubygems_version: 3.0.3
|
125
|
+
signing_key:
|
125
126
|
specification_version: 4
|
126
|
-
summary:
|
127
|
+
summary: 'git-gsub: Newer version is written in Go and Ruby implementation is deprecated.
|
128
|
+
See https://github.com/fujimura/git-gsub'
|
127
129
|
test_files:
|
128
130
|
- spec/git_gsub_spec.rb
|