git-gsub 0.0.1 → 0.0.2
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/.travis.yml +5 -0
- data/README.md +2 -2
- data/Rakefile +6 -0
- data/git-gsub.gemspec +2 -0
- data/lib/git/gsub.rb +19 -2
- data/lib/git/gsub/version.rb +1 -1
- data/spec/git_gsub_spec.rb +54 -0
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c363dcd00c4ab0e54c0fa430f3a29afee9a97d28
|
4
|
+
data.tar.gz: 36b90dade3b854e75a0ef0cddd4ce49f2549f6df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b2d34e428df7e28e5a923fe7a82f119682d5b79303362654ca10b730180c8c2983d12e00b90a1f0aba8c9991c57f589c475f025a516a70e5eacb66b1e5d9dd
|
7
|
+
data.tar.gz: b2a884081c3f65ca051d849e0fb32b11b227b4092c51565f9f859834c37c6f9b226439023f5f5f93c6369a82e926ab3ccf61d6404f5dc65c4b33ffe6cf68c002
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# git-gsub
|
1
|
+
# git-gsub [](http://badge.fury.io/rb/git-gsub)[](https://travis-ci.org/fujimura/git-gsub)
|
2
2
|
|
3
3
|
A Git subcommand to do gsub in a repository
|
4
4
|
|
@@ -53,7 +53,7 @@ $ git gsub "git\/gsub" "svn\/gsub"
|
|
53
53
|
|
54
54
|
## Supported platforms
|
55
55
|
|
56
|
-
|
56
|
+
Maybe on many *nix like OS which has sed/gsed.
|
57
57
|
|
58
58
|
## Contributing
|
59
59
|
|
data/Rakefile
CHANGED
data/git-gsub.gemspec
CHANGED
data/lib/git/gsub.rb
CHANGED
@@ -17,11 +17,28 @@ module Git
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.gsub *args
|
20
|
-
from, to, path, = args
|
20
|
+
from, to, path, = args.map do |arg|
|
21
|
+
Shellwords.escape arg if arg
|
22
|
+
end
|
23
|
+
|
24
|
+
if to.nil?
|
25
|
+
abort "No argument to gsub was given"
|
26
|
+
end
|
21
27
|
|
22
28
|
target_files = (`git grep -l #{from} #{path}`).each_line.map(&:chomp).join ' '
|
23
29
|
|
24
|
-
|
30
|
+
if system_support_gsed?
|
31
|
+
system %|gsed -i "" s/#{from}/#{to}/g #{target_files}|
|
32
|
+
else
|
33
|
+
system %|sed -i "" -e s/#{from}/#{to}/g #{target_files}|
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.system_support_gsed?
|
40
|
+
`which gsed`
|
41
|
+
$?.success?
|
25
42
|
end
|
26
43
|
end
|
27
44
|
end
|
data/lib/git/gsub/version.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'git/gsub'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
describe 'git-gsub' do
|
7
|
+
def run_in_directory_with_a_file content
|
8
|
+
Dir.mktmpdir do |dir|
|
9
|
+
filename = "FOO"
|
10
|
+
Dir.chdir dir do
|
11
|
+
File.open(filename, 'w') { |f| f << content }
|
12
|
+
`git init`
|
13
|
+
`git config --local user.email "you@example.com"`
|
14
|
+
`git config --local user.name "Your Name"`
|
15
|
+
`git add .`
|
16
|
+
`git commit -m init`
|
17
|
+
yield filename
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should substitute files' do
|
23
|
+
run_in_directory_with_a_file "Git Subversion Bzr" do |filename|
|
24
|
+
Git::Gsub.gsub "Bzr", "Mercurial"
|
25
|
+
file = File.read(filename).chomp
|
26
|
+
expect(file).to eq "Git Subversion Mercurial"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should escape well' do
|
31
|
+
run_in_directory_with_a_file %|<h1 class="foo">| do |filename|
|
32
|
+
Git::Gsub.gsub %|<h1 class="foo">|, %|<h1 class="bar">|
|
33
|
+
file = File.read(filename).chomp
|
34
|
+
expect(file).to eq %|<h1 class="bar">|
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should raise error if second argument wasn\'t given' do
|
39
|
+
run_in_directory_with_a_file "Git Subversion Bzr" do |filename|
|
40
|
+
begin
|
41
|
+
Git::Gsub.gsub "Bzr"
|
42
|
+
rescue SystemExit => e
|
43
|
+
expect(e.message).to match /No argument/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not create backup file' do
|
49
|
+
run_in_directory_with_a_file "Git Subversion Bzr" do |filename|
|
50
|
+
Git::Gsub.gsub "Bzr", "Darcs"
|
51
|
+
expect(`ls`).to eql "FOO\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fujimura Daisuke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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'
|
41
69
|
description: A Git subcommand to do gsub in a repository
|
42
70
|
email:
|
43
71
|
- me@fujimuradaisuke.com
|
@@ -47,6 +75,7 @@ extensions: []
|
|
47
75
|
extra_rdoc_files: []
|
48
76
|
files:
|
49
77
|
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
50
79
|
- Gemfile
|
51
80
|
- LICENSE.txt
|
52
81
|
- README.md
|
@@ -55,6 +84,7 @@ files:
|
|
55
84
|
- git-gsub.gemspec
|
56
85
|
- lib/git/gsub.rb
|
57
86
|
- lib/git/gsub/version.rb
|
87
|
+
- spec/git_gsub_spec.rb
|
58
88
|
homepage: https://github.com/fujimura/git-gsub
|
59
89
|
licenses:
|
60
90
|
- MIT
|
@@ -79,5 +109,5 @@ rubygems_version: 2.2.0
|
|
79
109
|
signing_key:
|
80
110
|
specification_version: 4
|
81
111
|
summary: A Git subcommand to do gsub in a repository
|
82
|
-
test_files:
|
83
|
-
|
112
|
+
test_files:
|
113
|
+
- spec/git_gsub_spec.rb
|