<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/lighthouse_branch/commands/update.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_checkout.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_commit.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_delete.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_merge.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_pull.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_push.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_resolve.rb</filename>
    </added>
    <added>
      <filename>test/commands/test_update.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -13,10 +13,10 @@ Add your Lighthouse project settings to your repo's git config.
 lh-branch [ticket_id]: Creates a branch based on the ticket name.
     lh-branch 1 #=&gt; git checkout -b 1-ticket-title
 
-lh-branch push [ticket_id] [remote name]: Pushes the ticket's branch to the named remote.
+lh-branch push [ticket_id] [remote_name]: Pushes the ticket's branch to the named remote.
     lh-branch 1 origin #=&gt; git push origin 1-ticket-title
 
-lh-branch pull [ticket_id] [remote name]: Pulls the ticket's branch from the named remote.
+lh-branch pull [ticket_id] [remote_name]: Pulls the ticket's branch from the named remote.
     lh-branch 1 origin #=&gt; git pull origin 1-ticket-title
 
 lh-branch merge [ticket_id]: Merges the ticket's branch with the current branch.
@@ -28,7 +28,7 @@ lh-branch checkout [ticket_id]: Checks out the ticket's branch, making it the cu
 lh-branch delete [ticket_id]: Deletes the ticket's branch.
     lh-branch delete 1 #=&gt; git branch -d 1-ticket-title
 
-lh-branch delete_remote [ticket_id] [remote name]: Deletes the ticket's branch on the remote server.
+lh-branch delete_remote [ticket_id] [remote_name]: Deletes the ticket's branch on the remote server.
     lh-branch delete_remote 1 origin #=&gt; git push origin :1-ticket-title
 
 lh-branch commit [ticket_id] [message]: Creates a commit that references the ticket</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -22,7 +22,7 @@ end
 require 'rake/testtask'
 Rake::TestTask.new(:test) do |test|
   test.libs &lt;&lt; 'lib' &lt;&lt; 'test'
-  test.pattern = 'test/**/*_test.rb'
+  test.pattern = 'test/**/test_*.rb'
   test.verbose = true
 end
 
@@ -30,7 +30,7 @@ begin
   require 'rcov/rcovtask'
   Rcov::RcovTask.new do |test|
     test.libs &lt;&lt; 'test'
-    test.pattern = 'test/**/*_test.rb'
+    test.pattern = 'test/**/test_*.rb'
     test.verbose = true
   end
 rescue LoadError</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -5,13 +5,11 @@ require File.join(File.dirname(__FILE__), 'lighthouse_branch', 'command', 'base'
 Dir.glob(File.join(File.dirname(__FILE__), 'lighthouse_branch', 'commands', '**.rb')).each { |command| require command }
 
 class LighthouseBranch
-  def initialize(project)
-    @project = project
+  def self.repo
+    @repo ||= Grit::Repo.new(Dir.pwd)
   end
   
   def self.get_lighthouse_account
-    repo = Grit::Repo.new(Dir.pwd)
-
     Lighthouse.account = repo.config[&quot;lighthouse.account&quot;]
     Lighthouse.token = repo.config[&quot;lighthouse.token&quot;]
     
@@ -30,33 +28,47 @@ class LighthouseBranch
     Lighthouse::Ticket.find(id, :params =&gt; { :project_id =&gt; @project.id })
   end
   
-  def branch_name(id)
-    &quot;#{id}-#{ticket(id).title.gsub(/[^\w ]/, '').gsub(/[^a-z0-9]+/i, '-').downcase}&quot;
+  def self.branch_name
+    unless @branch_name
+      if(Float(args.first) rescue false)
+        ticket_id = args.shift
+        @branch_name = &quot;#{ticket_id}-#{ticket(ticket_id).title.gsub(/[^\w ]/, '').gsub(/[^a-z0-9]+/i, '-').downcase}&quot;
+      else
+        @branch_name = repo.head.name
+      end
+    end
+    
+    return @branch_name
   end
   
   def self.invoke(args)
     get_lighthouse_account
     
+    command = :default
     if Command::Base.command_regexes.select{ |command| args.first =~ command }.empty?
-      unless (true if Float(args.first) rescue false)
+      ticket_id = branch_name.to_i
+      if ticket_id == 0
         usage
         exit
       end
+    else
+      command = args.shift
+      ticket_id = branch_name.to_i
     end
     
-    Command::Base.invoke(args, new(@project))
+    Command::Base.invoke(command, branch_name, ticket_id, args)
   end
   
   def self.usage
     puts &quot;Usage:&quot;
-    puts &quot;lh-branch [ticket_id]&quot;
-    puts &quot;lh-branch push [ticket_id] [remote name]&quot;
-    puts &quot;lh-branch pull [ticket_id] [remote name]&quot;
+    puts &quot;lh-branch [ticket_id] ([remote_name])&quot;
+    puts &quot;lh-branch push [ticket_id] [remote_name]&quot;
+    puts &quot;lh-branch pull [ticket_id] [remote_name]&quot;
     puts &quot;lh-branch merge [ticket_id]&quot;
     puts &quot;lh-branch checkout [ticket_id]&quot;
-    puts &quot;lh-branch commit [ticket_id] [message]&quot;
-    puts &quot;lh-branch delete [ticket_id]&quot;
-    puts &quot;lh-branch delete_remote [ticket_id] [remote name]&quot;
+    puts &quot;lh-branch update [ticket_id] [message] ([extra])&quot;
+    puts &quot;lh-branch delete [ticket_id] ([remote_name])&quot;
+    puts &quot;lh-branch delete_remote [ticket_id] [remote_name]&quot;
     puts &quot;lh-branch resolve [ticket_id] [message]&quot;
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,8 +15,12 @@ module Command
       self.class_eval(&quot;@@number_of_arguments = #{arguments}&quot;)
     end
     
-    def self.usage(usage)
-      self.class_eval(&quot;@@usage = \&quot;#{usage}\&quot;&quot;)
+    def self.usage(usage=nil)
+      if usage
+        return self.class_eval(&quot;@@usage = \&quot;#{usage}\&quot;&quot;)
+      else
+        return self.class_eval(&quot;@@usage&quot;)
+      end
     end
     
     def self.commands
@@ -25,10 +29,20 @@ module Command
     
     def self.run(lighthouse_branch, ticket, args)
       return unless defined?(:command_string)
-      unless args.size == (self.class_eval(&quot;@@number_of_arguments&quot;) || 0)
-        puts self.class_eval(&quot;@@usage&quot;) and exit
-      else
+      
+      number_of_arguments = (self.class_eval(&quot;@@number_of_arguments&quot;) || 0)
+      
+      correct_arguments = false
+      if number_of_arguments.is_a?(Range)
+        correct_arguments = number_of_arguments.member?(args.size)
+      elsif number_of_arguments.is_a?(Fixnum)
+        correct_arguments = number_of_arguments == args.size
+      end
+      
+      if correct_arguments
         system(self.command_string(lighthouse_branch, ticket, args))
+      else
+        puts self.usage and exit
       end
     end
     
@@ -36,18 +50,14 @@ module Command
       @@commands.keys.map { |k| /#{k}/i }
     end
     
-    def self.invoke(args, lighthouse_branch)
-      command = @@commands[args[0].to_s.downcase.to_sym]
-      if command
-        args.shift
-      else
+    def self.invoke(command, branch_name, ticket_id, args)
+      command = @@commands[command.to_s.downcase.to_sym]
+      if !command
         command = @@commands[:default]
       end
       
-      ticket_id = args.shift.to_i
-      
       return nil if ticket_id &lt;= 0
-      command.run(lighthouse_branch, ticket_id, args)
+      command.run(branch_name, ticket_id, args)
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/command/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,16 @@
 module Command
   class Branch &lt; Command::Base
     default_command
-    number_of_arguments 0
+    number_of_arguments (0..1)
     
     usage &quot;lh-branch [ticket_id]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git checkout -b #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      command_string = &quot;git checkout -b #{branch_name}&quot;
+      if remote_name = args.shift
+        command_string += &quot;; #{Command::Push.command_string(branch_name, ticket_id, remote_name.to_a)}&quot;
+      end
+      return command_string
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/branch.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@ module Command
     
     usage &quot;lh-branch checkout [ticket_id]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git checkout #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      &quot;git checkout #{branch_name}&quot;
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/checkout.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module Command
     
     usage &quot;lh-branch commit [ticket_id] [message]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
+    def self.command_string(branch_name, ticket_id, args)
       &quot;git commit -a -m \&quot;#{args.shift}\n\n[##{ticket_id}]\&quot;&quot;
     end
   end</diff>
      <filename>lib/lighthouse_branch/commands/commit.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,17 @@
 module Command
   class Delete &lt; Command::Base
     command_name :delete
-    number_of_arguments 0
+    number_of_arguments (0..1)
     
-    usage &quot;lh-branch delete [ticket_id]&quot;
+    usage &quot;lh-branch delete [ticket_id] ([remote_name])&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git branch -d #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      command_string = &quot;git branch -d #{branch_name}&quot;
+      if !args.empty?
+        remote_name = args.shift
+        command_string +=&quot;; git push #{remote_name} :#{branch_name}&quot;
+      end
+      return command_string
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/delete.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@ module Command
     
     usage &quot;lh-branch merge [ticket_id]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git merge #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      &quot;git merge #{branch_name}&quot;
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/merge.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,10 @@ module Command
     command_name :pull
     number_of_arguments 1
     
-    usage &quot;lh-branch pull [ticket_id] [remote name]&quot;
+    usage &quot;lh-branch pull [ticket_id] [remote_name]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git pull #{args.shift} #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      &quot;git pull #{args.shift} #{branch_name}&quot;
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/pull.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,10 @@ module Command
     command_name :push
     number_of_arguments 1
     
-    usage &quot;lh-branch push [ticket_id] [remote name]&quot;
+    usage &quot;lh-branch push [ticket_id] [remote_name]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
-      &quot;git push #{args.shift} #{lighthouse_branch.branch_name(ticket_id)}&quot;
+    def self.command_string(branch_name, ticket_id, args)
+      &quot;git push #{args.shift} #{branch_name}&quot;
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/lighthouse_branch/commands/push.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ module Command
     number_of_arguments 1
     usage &quot;lh-branch resolve [ticket_id] [message]&quot;
     
-    def self.command_string(lighthouse_branch, ticket_id, args)
+    def self.command_string(branch_name, ticket_id, args)
       &quot;git commit -a -m \&quot;#{args.shift}\n\n[##{ticket_id} state:resolved]\&quot;&quot;
     end
   end</diff>
      <filename>lib/lighthouse_branch/commands/resolve.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,11 @@
 require 'test_helper'
 
+module Command
+  class Base
+    @@commands = {}
+  end
+end
+
 class DefaultCommand &lt; Command::Base
   default_command
 end
@@ -22,7 +28,7 @@ class TestCommandBase &lt; Test::Unit::TestCase
   end
   
   should &quot;have a list of regexes to match&quot; do
-    regexes = [/named/i, /default/i]
-    assert_equal(regexes, Command::Base.command_regexes)
+    assert(Command::Base.command_regexes.include?(/named/i))
+    assert(Command::Base.command_regexes.include?(/default/i))
   end
 end
\ No newline at end of file</diff>
      <filename>test/command/test_base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -0,0 +1,17 @@
+require 'test_helper'
+
+class TestBranchCommand &lt; Test::Unit::TestCase
+  should &quot;create the branch with no arguments&quot; do
+    assert_equal(&quot;git checkout -b 1-test-ticket&quot;, \
+      Command::Branch.command_string('1-test-ticket', 1, []))
+  end
+  
+  should &quot;create the branch and push to remote with an argument&quot; do
+    assert_equal(&quot;git checkout -b 1-test-ticket; git push origin 1-test-ticket&quot;, 
+      Command::Branch.command_string('1-test-ticket', 1, ['origin']))
+  end
+  
+  should &quot;have usage instructions&quot; do
+    assert_equal(&quot;lh-branch [ticket_id]&quot;, Command::Branch.usage)
+  end
+end
\ No newline at end of file</diff>
      <filename>test/commands/test_branch.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/lighthouse_branch/commands/delete_remote.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>7234f4f48037f7dfc3446788b23408a2cbb51f67</id>
    </parent>
  </parents>
  <author>
    <name>Matt Pruitt</name>
    <email>guitsaru@gmail.com</email>
  </author>
  <url>http://github.com/guitsaru/lighthouse_branch/commit/8a074cc62e583b64199cbaf0f283295c741ed9d3</url>
  <id>8a074cc62e583b64199cbaf0f283295c741ed9d3</id>
  <committed-date>2009-06-23T19:03:00-07:00</committed-date>
  <authored-date>2009-06-23T19:03:00-07:00</authored-date>
  <message>Added tests for commands.  Added Technoweenie's commands.  Determine ticket from current branch name.

[#2 tagged:'branch:2-create-command-classes']</message>
  <tree>6b872a715a2e4b40e28197d10d3ae2c02819055c</tree>
  <committer>
    <name>Matt Pruitt</name>
    <email>guitsaru@gmail.com</email>
  </committer>
</commit>
