Class: Absgit
- Inherits:
-
Object
- Object
- Absgit
- Includes:
- Methadone::CLILogging, Utils
- Defined in:
- lib/absgit.rb,
lib/absgit/version.rb
Constant Summary collapse
- GIT_DIR_BASE =
'.git'- PROGRAM_NAME =
'absgit'- VERSION =
'0.2.1'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Absgit
constructor
A new instance of Absgit.
- #option_parser ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Absgit
Returns a new instance of Absgit.
14 15 16 17 |
# File 'lib/absgit.rb', line 14 def initialize(args) @args = args.dup = {} end |
Class Method Details
.get_repo_path(file_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/absgit.rb', line 19 def self.get_repo_path(file_name) Pathname.new(file_name).ascend do |path| if path.exist? path.realpath.ascend do |path2| if (path2 + '.git').exist? return path2 end end end end end |
Instance Method Details
#option_parser ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/absgit.rb', line 31 def option_parser OptionParser.new do |parser| parser.program_name = PROGRAM_NAME parser. = "Usage: #{PROGRAM_NAME} [options] [GIT_SUBCOMMAND]" parser.on('--debug', 'Show debugging information') do [:debug] = true end parser.on('--help', 'Show this usage summary') do [:help] = true end parser.on('--version', 'Show program name and version') do [:version] = true end end end |
#run ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/absgit.rb', line 50 def run begin option_parser.order! rescue OptionParser::ParseError $stderr.puts 'Error: incorrect usage' $stderr.puts '' $stderr.puts option_parser exit(1) end if [:debug] logger.error_level = Logger::Severity::DEBUG end debug(.inspect) debug(@args.inspect) if [:version] puts "#{PROGRAM_NAME} #{VERSION}" elsif [:help] puts option_parser else repo_path = @args[1..-1].find_all { |arg| repo_object_candidate?(arg) }. each_with_object(nil) { |arg| repo = self.class.get_repo_path(arg) break repo if !repo.nil? } if repo_path.nil? env = {} git_args = @args else env = { 'GIT_DIR' => (repo_path + GIT_DIR_BASE).to_s, 'GIT_WORK_TREE' => repo_path.to_s, } git_args = @args.map { |arg| make_tracked_files_relative_to_repo(repo_path, arg) } end command = ['git'] + git_args debug(command.inspect) debug(env.inspect) system(env, *command) # #< it seems better to use environment variables # rather than "--git-dir" and "--work-tree", because # environment variables will be inherited by processes # spawned by git aliases. exit($?.exited? ? $?.exitstatus: 1) end end |