Class: Fgit::CLI

Inherits:
Thor
  • Object
show all
Includes:
Common
Defined in:
lib/fgit/cli.rb

Instance Method Summary collapse

Instance Method Details

#cp(source_branch, file_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fgit/cli.rb', line 23

def cp(source_branch, file_name)
  if !options[:force] && status = local_changes
    puts "[Warning] There are unstaged local changes."
    puts status
    print "Copy files may override these changes. Continue? [yN]:"
    return unless !!(STDIN.gets.chomp =~ /^\s*[yY]\s*$/)
  end

  real_file_paths = ls(source_branch, file_name)

  if !options[:force]
    file_count = real_file_paths.split.compact.size
    file_string = file_count <= 1 ? "file" : "files"
    print "Copy #{file_count} #{file_string} above to current branch? [yN]:"
    return unless !!(STDIN.gets.chomp =~ /^\s*[yY]\s*$/)
  end

  unless real_file_paths.empty?
    puts "Handling..."
    `#{cp_command(source_branch, file_name)}`
    puts "Done."
  end
end

#ls(source_branch = nil, file_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fgit/cli.rb', line 8

def ls(source_branch=nil, file_name)
  branch = source_branch.nil? ? "HEAD" : "#{source_branch}"

  real_file_paths = `#{ls_command(branch, file_name)}`

  if real_file_paths.empty?
    $stderr.puts "[Error] #{file_name} can not be found!<branch: #{branch}>"
  else
    puts real_file_paths
  end
  real_file_paths
end