Skip to content

Commit

Permalink
map commit options and pass through to git. make readme more clear on…
Browse files Browse the repository at this point in the history
… usage.
  • Loading branch information
ryanbriones committed Nov 4, 2008
1 parent 8d1a666 commit 9294cf9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
9 changes: 5 additions & 4 deletions README.markdown
Expand Up @@ -21,11 +21,12 @@ I wanted a way for git to show me when a commit was made from a pair during pair


# Usage # Usage


* Add an author: `git-pair add abbr 'Person <emailaddress>'` * Add an author: `git-pair add [--global] abbr 'Person <emailaddress>'`
* example: `git-pair add js 'John Smith <jsmith@example.com>'` * example: `git-pair add --global js 'John Smith <jsmith@example.com>'` # adds pair to ~/.gitconfig
* example: `git-pair add js 'John Smith <jsmith@example.com>'` # WARNING adds pair to current git repo
* Show available authors: `git-pair show` * Show available authors: `git-pair show`
* Commit with a pair: `git-pair commit [abbr] [-m 'Commit Message']` * Commit with a pair: `git-pair commit [abbr] [git_options]`


# Authors # Authors


* [Ryan Carmelo Briones &lt;ryan.briones@brionesandco.com&gt;](mailto:ryan.briones@brionesandco.com) * [Ryan Carmelo Briones &lt;ryan.briones@brionesandco.com&gt;](mailto:ryan.briones@brionesandco.com)
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -3,7 +3,7 @@ require 'rake/gempackagetask'


spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'git-pair' s.name = 'git-pair'
s.version = '0.0.2' s.version = '0.0.3'
s.summary = 'Simple interface for adding your pair to a commit via git commit --author' s.summary = 'Simple interface for adding your pair to a commit via git commit --author'
s.files = FileList['[A-Z]*', 'bin/*', 'lib/**/*'] s.files = FileList['[A-Z]*', 'bin/*', 'lib/**/*']
s.has_rdoc = false s.has_rdoc = false
Expand Down
4 changes: 2 additions & 2 deletions git-pair.gemspec
@@ -1,10 +1,10 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{git-pair} s.name = %q{git-pair}
s.version = "0.0.2" s.version = "0.0.3"


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ryan Carmelo Briones"] s.authors = ["Ryan Carmelo Briones"]
s.date = %q{2008-10-28} s.date = %q{2008-11-03}
s.default_executable = %q{git-pair} s.default_executable = %q{git-pair}
s.email = %q{ryan.briones@brionesandco.com} s.email = %q{ryan.briones@brionesandco.com}
s.executables = ["git-pair"] s.executables = ["git-pair"]
Expand Down
36 changes: 27 additions & 9 deletions lib/git-pair/command.rb
Expand Up @@ -5,7 +5,7 @@
module GitPair module GitPair
class Command class Command
def initialize def initialize
@options = {} @options = {:passthru => []}
@sub_command = nil @sub_command = nil
@sub_args = [] @sub_args = []
end end
Expand All @@ -22,32 +22,50 @@ def run_sub_command
return GitPair::Author.show return GitPair::Author.show
when "add" when "add"
unless @sub_args.length == 2 unless @sub_args.length == 2
puts %Q(Usage: #{$0} add js "John Smith <jsmith@example.com>") puts %Q(Usage: #{$0} add [--global] js "John Smith <jsmith@example.com>")
return 1 return 1
end end


return GitPair::Author.add(@sub_args[0], @sub_args[1], @options) return GitPair::Author.add(@sub_args[0], @sub_args[1], @options)
when "commit" when "commit"
return GitPair::Commit.commit(@options[:message], @sub_args[0]) pair_abbr = @sub_args.shift
passthru = "#{@options[:passthru].join(' ')} -- #{@sub_args.join(' ')}"

return GitPair::Commit.commit(pair_abbr, passthru)
else else
puts %Q(Usage: #{$0} show) puts %Q(Usage: #{$0} show)
puts %Q(Usage: #{$0} add js "John Smith <jsmith@example.com>") puts %Q(Usage: #{$0} add [--global] js "John Smith <jsmith@example.com>")
puts %Q(Usage: #{$0} commit [pair] [-m <msg>] ) puts %Q(Usage: #{$0} commit [pair] [git_options])
return 0 return 0
end end
end end


def parse(args) def parse(args)
OptionParser.new do |opts| OptionParser.new do |opts|


opts.on('-m <msg>') do |m|
@options[:message] = m
end

opts.on('--global') do |g| opts.on('--global') do |g|
@options[:global] = g @options[:global] = g
end end


# git commit options
opts.on('-a', '--all') { |a| @options[:passthru] << "-a"}
opts.on('-C <commit>', '--reuse-message=<commit>') { |c| @options[:passthru] << "-C #{c}" }
opts.on('-c <commit>', '--reedit-message=<commit>') { |c| @options[:passthru] << "-c #{c}" }
opts.on('-F <file>', '--file=<file>') { |f| @options[:passthru] << %Q(-F "#{f}") }
opts.on('-m <msg>', '--message=<msg>') { |m| @options[:passthru] << %Q(-m "#{m}") }
opts.on('-t <file>', '--template=<file>') { |t| @options[:passthru] << %Q(-t "#{t}") }
opts.on('-s', '--signoff') { |s| @options[:passthru] << "-s" }
opts.on('-n', '--no-verify') { |n| @options[:passthru] << "-n" }
opts.on('--allow-empty') { |ae| @options[:passthru] << "--allow-empty" }
opts.on('--cleanup=<mode>') { |cl| @options[:passthru] << "-cleanup=#{cl}" }
opts.on('-e', '--edit') { |e| @options[:passthru] << "-e" }
opts.on('--amend') { |am| @options[:passthru] << "--amend" }
opts.on('-i', '--include') { |i| @options[:passthru] << "-i" }
opts.on('-o', '--only') { |o| @options[:passthru] << "-o" }
opts.on('-u[<mode>]', '--untracked-files[=<mode>]') { |u| @options[:passthru] << "-u#{u}" }
opts.on('-v', '--verbose') { |v| @options[:passthru] << "-v" }
opts.on('-q', '--quiet') { |q| @options[:passthru] << "-q" }

opts.parse!(args) opts.parse!(args)


end end
Expand Down
12 changes: 5 additions & 7 deletions lib/git-pair/commit.rb
Expand Up @@ -2,16 +2,14 @@


module GitPair module GitPair
class Commit class Commit
def self.commit(message, pair_abbr) def self.commit(pair_abbr, git_args)
base_command = "git commit" command = "git commit"


author = GitPair::Author.find_by_abbr(pair_abbr) author = GitPair::Author.find_by_abbr(pair_abbr)

args = []
args << %Q(-m "#{message}") unless message.nil? || message.empty?
args << %Q(--author="#{author}") if author


command = "#{base_command} #{args.join(' ')}" command << %Q( --author="#{author}") if author
command << " #{git_args}" if git_args && git_args != ""

system(command) system(command)
return $? return $?
end end
Expand Down

0 comments on commit 9294cf9

Please sign in to comment.