Top Level Namespace
Defined Under Namespace
Modules: Gitan
Constant Summary collapse
- OPTIONS =
main
{}
- OPTION_PARSER =
OptionParser.new
Instance Method Summary collapse
- #add_argument_option ⇒ Object
- #add_remote_option ⇒ Object
- #commit ⇒ Object
- #execute(path, command) ⇒ Object
- #heads ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #repositories(remote_heads = {}) ⇒ Object
- #show_usage ⇒ Object
- #status ⇒ Object
Instance Method Details
#add_argument_option ⇒ Object
53 54 55 56 57 |
# File 'bin/gitan', line 53 def add_argument_option OPTION_PARSER.on("-a str", "--arguments=str", "supply argument to command"){ |str| OPTIONS[:argument] = str } end |
#add_remote_option ⇒ Object
46 47 48 49 50 51 |
# File 'bin/gitan', line 46 def add_remote_option OPTION_PARSER.on("-r remote_dir", "--remote=dir", "with remote info"){ |remote_dir| server, path = remote_dir.split(":") OPTIONS[:remote] = Gitan.remote_heads(server, path) } end |
#commit ⇒ Object
116 117 118 119 120 121 122 |
# File 'bin/gitan', line 116 def commit add_argument_option OPTION_PARSER.parse!(ARGV) repositories.select {|repo| repo.to_be_commited?}.each do |repo| execute(repo.path, "git commit #{OPTIONS[:argument]}") end end |
#execute(path, command) ⇒ Object
76 77 78 79 80 81 |
# File 'bin/gitan', line 76 def execute(path, command) print "#{path}: " Dir.chdir path puts command system command unless OPTIONS[:debug] end |
#heads ⇒ Object
108 109 110 111 112 113 114 |
# File 'bin/gitan', line 108 def heads results = {} repositories.each do |repo| results[repo.path] = repo.head end YAML.dump(results, $stdout) end |
#pull ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'bin/gitan', line 133 def pull add_remote_option add_argument_option OPTION_PARSER.parse!(ARGV) repositories.select {|repo| repo.to_be_pulled?}.each do |repo| execute(repo.path, "git pull #{OPTIONS[:argument]}") end end |
#push ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'bin/gitan', line 124 def push add_argument_option OPTION_PARSER.parse!(ARGV) repositories.select {|repo| repo.to_be_pushed?}.each do |repo| execute(repo.path, "git push #{OPTIONS[:argument]}") end end |
#repositories(remote_heads = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'bin/gitan', line 59 def repositories(remote_heads = {}) git_dir = ENV["HOME"] + "/git" git_dir = File::(ARGV[0]) if ARGV[0] dirs = Dir.glob(git_dir + "/*").sort.map do |path| if File.directory? path remote_head = nil remote_head = OPTIONS[:remote][File.basename(path)] if OPTIONS[:remote] Gitan::Repo.new(path, remote_head) else nil end end dirs.select{|dir| dir} end |
#show_usage ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'bin/gitan', line 26 def show_usage puts <<-HERE USAGE gitan heads [path]" gitan status [path] [-r remote_dir]" gitan commit [path] [-a arguments]" gitan push [path] [-a arguments]" gitan pull [path] [-a arguments] [-r remote_dir]" Default value of 'path' is ~/git. Examples: gitan heads /home/git gitan status -r example.com:/home/git gitan commit --argument='-am "commit message"' gitan push -a "origin master" gitan pull ~/git -r example.com:/home/git -a "origin master" HERE end |
#status ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'bin/gitan', line 83 def status add_remote_option OPTION_PARSER.on("-a", "--all", "show all repositories."){ OPTIONS[:all] = true} OPTION_PARSER.on("-e", "--explain", "show explanation for abbreviation."){ OPTIONS[:explain] = true} OPTION_PARSER.parse!(ARGV) repos = repositories unless OPTIONS[:all] repos = repos.select do |repo| result = false result = true if repo.multiple_branch? result = true if repo.to_be_staged? result = true if repo.to_be_commited? result = true if repo.to_be_pushed? result = true if (OPTIONS[:remote] && repo.to_be_pulled?) result end end Gitan::Repo.show_abbreviation if OPTIONS[:explain] repos.each do |repo| puts repo.short_status end end |