Skip to content
Browse files

initial commit; basic working version

  • Loading branch information...
0 parents commit 72f94e638a24e52a2f4a4cf95c9db9a1fb36d9c4 @ryanbriones committed
Showing with 171 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +26 −0 Rakefile
  3. +5 −0 bin/git-pair
  4. +26 −0 git-pair.gemspec
  5. +35 −0 lib/git-pair/author.rb
  6. +59 −0 lib/git-pair/command.rb
  7. +19 −0 lib/git-pair/commit.rb
1 .gitignore
@@ -0,0 +1 @@
+pkg/*
26 Rakefile
@@ -0,0 +1,26 @@
+require 'rubygems'
+require 'rake/gempackagetask'
+
+spec = Gem::Specification.new do |s|
+ s.name = 'git-pair'
+ s.version = '0.0.1'
+ s.summary = 'Simple interface for adding your pair to a commit via git commit --author'
+ s.files = FileList['[A-Z]*', 'bin/*', 'lib/*']
+ s.has_rdoc = false
+ s.bindir = 'bin'
+ s.executables = ['git-pair']
+ s.default_executable = 'git-pair'
+ s.author = 'Ryan Carmelo Briones'
+ s.email = 'ryan.briones@brionesandco.com'
+ s.homepage = 'http://brionesandco.com/ryanbriones'
+end
+
+package_task = Rake::GemPackageTask.new(spec) {}
+
+task :build_gemspec do
+ File.open("#{spec.name}.gemspec", "w") do |f|
+ f.write spec.to_ruby
+ end
+end
+
+task :default => [:build_gemspec, :gem]
5 bin/git-pair
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+require 'git-pair/command'
+
+exit GitPair::Command.run!(ARGV)
26 git-pair.gemspec
@@ -0,0 +1,26 @@
+Gem::Specification.new do |s|
+ s.name = %q{git-pair}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Ryan Carmelo Briones"]
+ s.date = %q{2008-10-28}
+ s.default_executable = %q{git-pair}
+ s.email = %q{ryan.briones@brionesandco.com}
+ s.executables = ["git-pair"]
+ s.files = ["Rakefile", "bin/git-pair", "lib/git-pair"]
+ s.homepage = %q{http://brionesandco.com/ryanbriones}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.2.0}
+ s.summary = %q{Simple interface for adding your pair to a commit via git commit --author}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if current_version >= 3 then
+ else
+ end
+ else
+ end
+end
35 lib/git-pair/author.rb
@@ -0,0 +1,35 @@
+module GitPair
+ class Author
+ def self.add(abbr, email, options = {})
+ base_command = "git config"
+
+ args = []
+ args << "--global" if options[:global]
+ args << "git-pair.authors.#{abbr}"
+ args << %Q("#{email}")
+
+ command = "#{base_command} #{args.join(' ')}"
+ system(command)
+ return $?
+ end
+
+ def self.show
+ author_regex = /^git-pair.authors.([^=]+)=(.+)$/
+ authors = `git config --list | grep 'git-pair'`
+
+ puts "Authors"
+ puts "========"
+
+ authors.each_line do |line|
+ line =~ author_regex
+ puts "#{$1} - #{$2}"
+ end
+ return 0
+ end
+
+ def self.find_by_abbr(pair_abbr)
+ pair = `git config git-pair.authors.#{pair_abbr}`.chomp
+ return pair unless pair.empty?
+ end
+ end
+end
59 lib/git-pair/command.rb
@@ -0,0 +1,59 @@
+require 'optparse'
+require 'git-pair/author'
+require 'git-pair/commit'
+
+module GitPair
+ class Command
+ def initialize
+ @options = {}
+ @sub_command = nil
+ @sub_args = []
+ end
+
+ def self.run!(argv)
+ command = self.new
+ command.parse(argv)
+ command.run_sub_command
+ end
+
+ def run_sub_command
+ case @sub_command
+ when "show"
+ return GitPair::Author.show
+ when "add"
+ unless @sub_args.length == 2
+ puts %Q(Usage: #{$0} add js "John Smith <jsmith@example.com>")
+ return 1
+ end
+
+ return GitPair::Author.add(@sub_args[0], @sub_args[1], @options)
+ when "commit"
+ return GitPair::Commit.commit(@options[:message], @sub_args[0])
+ else
+ puts %Q(Usage: #{$0} show)
+ puts %Q(Usage: #{$0} add js "John Smith <jsmith@example.com>")
+ puts %Q(Usage: #{$0} commit [pair] [-m <msg>] )
+ return 0
+ end
+ end
+
+ def parse(args)
+ OptionParser.new do |opts|
+
+ opts.on('-m <msg>') do |m|
+ @options[:message] = m
+ end
+
+ opts.on('--global') do |g|
+ @options[:global] = g
+ end
+
+ opts.parse!(args)
+
+ end
+
+ @sub_command = args.shift
+ @sub_args = args
+ end
+ end
+end
19 lib/git-pair/commit.rb
@@ -0,0 +1,19 @@
+require 'git-pair/author'
+
+module GitPair
+ class Commit
+ def self.commit(message, pair_abbr)
+ base_command = "git commit"
+
+ 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(' ')}"
+ system(command)
+ return $?
+ end
+ end
+end

0 comments on commit 72f94e6

Please sign in to comment.
Something went wrong with that request. Please try again.