class Fgit::CLI

Public Instance Methods

cp(source_branch, file_name) click to toggle source
# 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) click to toggle source
# 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