Class: Fgit::CLI
- Inherits:
-
Thor
- Object
- Thor
- Fgit::CLI
- Defined in:
- lib/fgit/cli.rb
Instance Method Summary collapse
Instance Method Details
#cp(source_branch, file_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fgit/cli.rb', line 21 def cp(source_branch, file_name) status = `git status -s` unless status.empty? $stderr.puts "[Warning] Please commit or stash your local changes." $stderr.puts status return end real_file_paths = ls(source_branch, file_name) unless real_file_paths.empty? copy_command = "git ls-tree -r --name-only #{source_branch} | grep -E '^(.*/)*#{file_name}$' | xargs git checkout #{source_branch}" puts "Handling..." `#{copy_command}` puts "Done." end end |
#ls(source_branch = nil, file_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fgit/cli.rb', line 6 def ls(source_branch=nil, file_name) branch = source_branch.nil? ? "HEAD" : "#{source_branch}" command= "git ls-tree -r --name-only #{branch} | grep -E '^(.*/)*#{file_name}$'" real_file_paths = `#{command}` if real_file_paths.empty? $stderr.puts "[Error] #{file_name} can not be found!<branch: #{source_branch}>" else puts real_file_paths end real_file_paths end |