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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33f69edca87b9d1b9697e6154bc97600d7f011c0
4
- data.tar.gz: d61c551f0cb7d57ae3ba2a7ad4a6290228925d7d
3
+ metadata.gz: 60fb839e06a3123640ed2bd5fef845f020758de8
4
+ data.tar.gz: 17b642ae884897efd0fc605deff626428cd69da2
5
5
  SHA512:
6
- metadata.gz: 8ff16147e61fcc06fdee4080db2480bd9213b1e02a27c127a5ee3eddd92e2b2ed982ea6962e567424c4bc9d4dd6ae0cc3645e64936027a6ed2fe3a3a22783cad
7
- data.tar.gz: d4ab1d6cf06f171e0bbd6ab4a8f152bcfb0e573c72330109e7e66d28d24dc1e7c5d4409b451b0dc831bdc11582e55575a491aa8f91869900b814262372b23ddd
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
- ## Development
28
+ ```
29
+ Commands:
30
+ fgit ls BRANCH FILE_NAME
28
31
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
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'`)
@@ -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{extend git for file manipulating from branch to branch}
13
- spec.description = %q{extend git for file manipulating from branch to branch}
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
 
@@ -1,2 +1,6 @@
1
1
  require "fgit/version"
2
- require "fgit/cli"
2
+
3
+ module Fgit
4
+ autoload :Common, "fgit/common"
5
+ autoload :CLI, "fgit/cli"
6
+ end
@@ -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 = `#{command}`
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: #{source_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
- status = `git status -s`
23
-
24
- unless status.empty?
25
- $stderr.puts "[Warning] Please commit or stash your local changes."
26
- $stderr.puts status
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
- `#{copy_command}`
42
+ `#{cp_command(source_branch, file_name)}`
35
43
  puts "Done."
36
44
  end
37
45
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Fgit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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-07 00:00:00.000000000 Z
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: extend git for file manipulating from branch to branch
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: extend git for file manipulating from branch to branch
101
+ summary: make command more easy to use for file manipulating from branch to branch
102
+ base on git command
100
103
  test_files: []