fgit 0.0.1 → 0.1.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 +4 -4
- data/README.md +11 -5
- data/fgit.gemspec +2 -2
- data/lib/fgit.rb +5 -1
- data/lib/fgit/cli.rb +20 -12
- data/lib/fgit/common.rb +26 -0
- data/lib/fgit/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60fb839e06a3123640ed2bd5fef845f020758de8
|
4
|
+
data.tar.gz: 17b642ae884897efd0fc605deff626428cd69da2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4146815b302e415e82c35e55e96ec9db6619f9c2a01a8210c6caee49e72a00da0b53e05ff33fb1b2c65e38f9fecfd43227441980c23e03dab90e85830f08f888
|
7
|
+
data.tar.gz: a9b9a34aa56a0f595484b0f98b40ac2037657c3cd0cce218a2c5b17402db756a6c47295c55be36da37fcd7821288235bae1ef856644804fcf143a3ab969ce4bb
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fgit`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
|
5
|
+
This tool is just make command more easy to use for file manipulating from branch to branch base on git command
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,16 +22,22 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
* list all relative file paths in given branch by a filename or a regular expression of filename
|
26
|
+
* copy all files from given branch by a filename or a regular expression of filename
|
26
27
|
|
27
|
-
|
28
|
+
```
|
29
|
+
Commands:
|
30
|
+
fgit ls BRANCH FILE_NAME
|
28
31
|
|
29
|
-
|
32
|
+
fgit cp BRANCH FILE_NAME
|
33
|
+
with --force -f option: force to copy all files without confirm and ignore unstaged local changes
|
34
|
+
```
|
30
35
|
|
31
|
-
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
36
|
|
33
37
|
## Contributing
|
34
38
|
|
39
|
+
Welcome any contrbutions to this project.
|
40
|
+
|
35
41
|
1. Fork it ( https://github.com/[my-github-username]/fgit/fork )
|
36
42
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
43
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/fgit.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["yan_runchen"]
|
10
10
|
spec.email = ["chen_0_1987@sina.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{make command more easy to use for file manipulating from branch to branch base on git command}
|
13
|
+
spec.description = %q{make command more easy to use for file manipulating from branch to branch base on git command}
|
14
14
|
spec.homepage = "https://github.com/SmileZero/fgit"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
data/lib/fgit.rb
CHANGED
data/lib/fgit/cli.rb
CHANGED
@@ -2,36 +2,44 @@ require "thor"
|
|
2
2
|
|
3
3
|
module Fgit
|
4
4
|
class CLI < Thor
|
5
|
+
include Common
|
6
|
+
|
5
7
|
desc "ls BRANCH FILE_NAME", "list file in the given branch"
|
6
8
|
def ls(source_branch=nil, file_name)
|
7
9
|
branch = source_branch.nil? ? "HEAD" : "#{source_branch}"
|
8
|
-
command= "git ls-tree -r --name-only #{branch} | grep -E '^(.*/)*#{file_name}$'"
|
9
10
|
|
10
|
-
real_file_paths = `#{
|
11
|
+
real_file_paths = `#{ls_command(branch, file_name)}`
|
11
12
|
|
12
13
|
if real_file_paths.empty?
|
13
|
-
$stderr.puts "[Error] #{file_name} can not be found!<branch: #{
|
14
|
+
$stderr.puts "[Error] #{file_name} can not be found!<branch: #{branch}>"
|
14
15
|
else
|
15
16
|
puts real_file_paths
|
16
17
|
end
|
17
18
|
real_file_paths
|
18
19
|
end
|
19
20
|
|
20
|
-
desc "cp BRANCH FILE_NAME", "copy file from the given branch"
|
21
|
+
desc "cp BRANCH FILE_NAME", "copy file from the given branch, with --force -f option: force to copy all files"
|
22
|
+
method_option :force, :type => :boolean, :aliases => "-f"
|
21
23
|
def cp(source_branch, file_name)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
return
|
24
|
+
if !options[:force] && status = local_changes
|
25
|
+
puts "[Warning] There are unstaged local changes."
|
26
|
+
puts status
|
27
|
+
print "Copy files may override these changes. Continue? [yN]:"
|
28
|
+
return unless !!(STDIN.gets.chomp =~ /^\s*[yY]\s*$/)
|
28
29
|
end
|
29
30
|
|
30
31
|
real_file_paths = ls(source_branch, file_name)
|
32
|
+
|
33
|
+
if !options[:force]
|
34
|
+
file_count = real_file_paths.split.compact.size
|
35
|
+
file_string = file_count <= 1 ? "file" : "files"
|
36
|
+
print "Copy #{file_count} #{file_string} above to current branch? [yN]:"
|
37
|
+
return unless !!(STDIN.gets.chomp =~ /^\s*[yY]\s*$/)
|
38
|
+
end
|
39
|
+
|
31
40
|
unless real_file_paths.empty?
|
32
|
-
copy_command = "git ls-tree -r --name-only #{source_branch} | grep -E '^(.*/)*#{file_name}$' | xargs git checkout #{source_branch}"
|
33
41
|
puts "Handling..."
|
34
|
-
`#{
|
42
|
+
`#{cp_command(source_branch, file_name)}`
|
35
43
|
puts "Done."
|
36
44
|
end
|
37
45
|
end
|
data/lib/fgit/common.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fgit
|
2
|
+
module Common
|
3
|
+
private
|
4
|
+
|
5
|
+
def local_changes
|
6
|
+
status = `git status -s`
|
7
|
+
|
8
|
+
return nil if status.empty?
|
9
|
+
status
|
10
|
+
end
|
11
|
+
|
12
|
+
def ls_command(branch, file_name)
|
13
|
+
ls_commands = []
|
14
|
+
ls_commands << "git ls-tree -r --name-only #{branch}"
|
15
|
+
ls_commands << "grep -E '^(.*/)*#{file_name}$'"
|
16
|
+
ls_commands.join("|")
|
17
|
+
end
|
18
|
+
|
19
|
+
def cp_command(branch, file_name)
|
20
|
+
cp_commands = []
|
21
|
+
cp_commands << ls_command(branch, file_name)
|
22
|
+
cp_commands << "xargs git checkout #{branch}"
|
23
|
+
cp_commands.join("|")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/fgit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fgit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yan_runchen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
-
description:
|
55
|
+
description: make command more easy to use for file manipulating from branch to branch
|
56
|
+
base on git command
|
56
57
|
email:
|
57
58
|
- chen_0_1987@sina.com
|
58
59
|
executables:
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- fgit.gemspec
|
73
74
|
- lib/fgit.rb
|
74
75
|
- lib/fgit/cli.rb
|
76
|
+
- lib/fgit/common.rb
|
75
77
|
- lib/fgit/version.rb
|
76
78
|
homepage: https://github.com/SmileZero/fgit
|
77
79
|
licenses:
|
@@ -96,5 +98,6 @@ rubyforge_project:
|
|
96
98
|
rubygems_version: 2.4.5
|
97
99
|
signing_key:
|
98
100
|
specification_version: 4
|
99
|
-
summary:
|
101
|
+
summary: make command more easy to use for file manipulating from branch to branch
|
102
|
+
base on git command
|
100
103
|
test_files: []
|