Browse files

Merge branch 'hotfix-1.0.2.12'

  • Loading branch information...
2 parents de62df1 + fe74098 commit 2ceb3676317f19b011fe2deca26e6bdff90fea0f @jeffWelling jeffWelling committed Jan 4, 2012
View
6 lib/ticgit-ng.rb
@@ -41,7 +41,11 @@ module TicGitNG
autoload :Ticket, 'ticgit-ng/ticket'
# options
- # :logger => Logger.new(STDOUT)
+ # :logger => Logger.new(STDOUT)
+ # :tic_dir => "~/.#{ which_branch?() }"
+ # :working_directory => File.expand_path(File.join(@tic_dir, proj, 'working'))
+ # :index_file => File.expand_path(File.join(@tic_dir, proj, 'index'))
+ # :init => Boolean -- if true, allow initializing ticgit
def self.open(git_dir, options = {})
Base.new(git_dir, options)
end
View
54 lib/ticgit-ng/base.rb
@@ -10,6 +10,19 @@ class Base
def initialize(git_dir, opts = {})
@git = Git.open(find_repo(git_dir))
+ @logger = opts[:logger] || Logger.new(STDOUT)
+
+ #This is to accomodate for edge-cases where @logger.puts
+ #is called from debugging code.
+ unless @logger.respond_to?(:puts)
+ def @logger.puts str
+ self.info str
+ end
+ end
+
+ @last_tickets = []
+ @init=opts[:init]
+
proj = Ticket.clean_string(@git.dir.path)
@tic_dir = opts[:tic_dir] || "~/.#{which_branch?}"
@@ -19,15 +32,23 @@ def initialize(git_dir, opts = {})
@logger = opts[:logger] || Logger.new(STDOUT)
@last_tickets = []
- #expire @tic_index and @tic_working if it mtime is older than git log
+ #expire @tic_index and @tic_working if it mtime is older than
+ #git log. Otherwise, during testing, if you use the same temp
+ #directory with the same name, deleting it and recreating it
+ #to test something, ticgit would get confused by the cache from
+ #the previous instance of the temp dir.
if File.exist?(@tic_working)
cache_mtime=File.mtime(@tic_working)
- gitlog_mtime=git.gblob(which_branch?).log(1).map {|l| l.committer.date }[0]
+ (gitlog_mtime=git.gblob(which_branch?).log(1).map {|l| l.committer.date }[0]) rescue reset_cache
+
#unless (cache_mtime > gitlog_mtime.-(20) and cache_mtime <= gitlog_mtime) or (cache_mtime > gitlog_mtime.+(30) and cache_mtime >= gitlog_mtime)
- if ((cache_mtime.to_i - gitlog_mtime.to_i) > 120) or ((gitlog_mtime.to_i - cache_mtime.to_i) > 120)
- puts "Resetting cache"
- reset_cache unless cache_mtime==gitlog_mtime
+ #FIXME break logic out into several lines
+ #FIXME don't bother resetting if gitlog_mtime.to_i == 0
+ if needs_reset?( cache_mtime, gitlog_mtime ) and !cache_mtime==gitlog_mtime
+ puts "Resetting cache" unless gitlog_mtime.to_i == 0
+ reset_cache
end
+
end
# load config file
@@ -313,7 +334,15 @@ def read_tickets
unless (bs.include?(which_branch?) || bs.include?(which_branch?)) &&
File.directory?(@tic_working)
- init_ticgitng_branch(bs.include?(which_branch?))
+ unless @init
+ puts "Please run `ti init` to initialize TicGit-ng for this repository before running other ti commands."
+ exit
+ else
+ puts "Initializing TicGit-ng"
+ init_ticgitng_branch(
+ git.lib.branches_all.map{|b| b.first }.include?(which_branch?)
+ )
+ end
end
tree = git.lib.full_tree(which_branch?)
@@ -331,7 +360,7 @@ def read_tickets
end
def init_ticgitng_branch(ticgitng_branch = false)
- @logger.info 'creating ticgit-ng repo branch'
+ @logger << 'creating ticgit-ng repo branch'
in_branch(ticgitng_branch) do
#The .hold file seems to have little to no purpose aside from helping
@@ -390,11 +419,18 @@ def which_branch?
def reset_cache
#@state, @tic_index, @tic_working
+ #A rescue is appended to the end of each line because it allows
+ #execution of others to continue upon failure, as opposed to
+ #a begin;rescue;end segment.
+ FileUtils.rm_r File.expand_path(@tic_working) rescue nil
FileUtils.rm File.expand_path(@state) rescue nil
FileUtils.rm File.expand_path(@tic_index) rescue nil
- FileUtils.rm_r File.expand_path(@tic_working) rescue nil
+ FileUtils.mkdir_p File.expand_path(@tic_working) rescue nil
@state=nil
- FileUtils.mkdir_p File.expand_path(@tic_working)
+ end
+
+ def needs_reset? cache_mtime, gitlog_mtime
+ ((cache_mtime.to_i - gitlog_mtime.to_i) > 120) or ((gitlog_mtime.to_i - cache_mtime.to_i) > 120)
end
end
View
22 lib/ticgit-ng/cli.rb
@@ -21,13 +21,23 @@ def self.parse(args)
def initialize(args, path = '.', out = $stdout)
@args = args.dup
- @tic = TicGitNG.open(path, :keep_state => true)
+
+ #set @init if one of the args is 'init'
+ #this needs to be done because initialization of the ticgit branch must be done before
+ #the branch is loaded, but because of the way commands are modularized this must be done
+ #outside of and before the init.rb file itself is called (init.rb is where we would
+ #normally put the code for such a command).
+ args.include?( 'init' ) ? (@init=true) : (@init=false)
+ #@init= ((args[0][/init/]=='init') rescue false)
+ #@init= ((args[0][/init/]=='init') or (args[1][/init/]=='init') rescue false)
+
+ @tic = TicGitNG.open(path, {:keep_state => true, :init => @init, :logger => out })
@options = OpenStruct.new
@out = out
@out.sync = true # so that Net::SSH prompts show up
rescue NoRepoFound
- puts "No repo found"
+ out.puts "No repo found"
exit
end
@@ -64,7 +74,13 @@ def parse_options! #:nodoc:
exit 1
end
- @action = args.shift
+ #FIXME
+ #this is a dirty hack that needs to be fixed
+ if args.include?('list') and args.include?('init')
+ @action = 'list'
+ else
+ @action = args.shift
+ end
end
def usage(args = nil)
View
1 lib/ticgit-ng/command.rb
@@ -22,6 +22,7 @@ def self.register(mod_name, doc, *commands)
register 'State', 'Change state of a ticket', 'state'
register 'Tag', 'Modify tags of a ticket', 'tag'
register 'Sync', 'Sync tickets', 'sync'
+ register 'Init', 'Initialize Ticgit-ng', 'init'
def self.get(command)
if mod_name = COMMANDS[command]
View
3 lib/ticgit-ng/command/assign.rb
@@ -10,7 +10,8 @@ module Command
# ti assign -u {name} {1} (assign specified ticket to specified user)
module Assign
def parser(opts)
- opts.banner = "Usage: ti assign [options] [ticket_id]"
+ opts.banner = "Usage: ti assign [options] [ticket_id]\n"+
+ "Note: to assign to nobody: ti assign -u ''"
opts.on_head(
"-u USER", "--user USER", "Assign the ticket to this user"){|v|
options.user = v
View
20 lib/ticgit-ng/command/init.rb
@@ -0,0 +1,20 @@
+module TicGitNG
+ module Command
+ module Init
+ def parser o
+ o.banner= "Usage: ti init"
+ end
+ def execute
+ @tic.read_tickets
+=begin
+ #Initialization has to happen earlier in the code so this code stands
+ #as an example, when `ti init` is called, initialization is handled by
+ #base.rb:354 (at the time of writing this).
+ tic.base.init_ticgitng_branch(
+ git.lib.branches_all.map{|b| b.first }.include?(which_branch?)
+ )
+=end
+ end
+ end
+ end
+end
View
2 lib/ticgit-ng/ticket.rb
@@ -86,7 +86,7 @@ def save_new
base.in_branch do |wd|
files=[]
t=nil
- base.logger.info "saving #{ticket_name}"
+ base.logger.puts "saving #{ticket_name}"
Dir.mkdir(ticket_name)
Dir.chdir(ticket_name) do
View
2 lib/ticgit-ng/version.rb
@@ -1,3 +1,3 @@
module TicGitNG
- VERSION = '1.0.2.11'
+ VERSION = '1.0.2.12'
end
View
4 spec/cli_spec.rb
@@ -56,10 +56,10 @@
# It's unclear why it's necessary to append each line like this, but
# cli('list') would otherwise return nil. The spec helper probably
# needs some refactoring.
- cli 'list' do |line|
+ cli('init','list') do |line|
output << line
end
- output.shift.should be_empty
+ output.shift.should match "creating ticgit-ng repo branch"
output.shift.should match /#{fields.join '\s+'}/
output.shift.should match /^-+$/
end
View
2 spec/spec_helper.rb
@@ -31,7 +31,7 @@ def setup_new_git_repo prefix='ticgit-ng-gitdir-'
def test_opts
tempdir = Dir.mktmpdir 'ticgit-ng-ticdir-'
logger = Logger.new(Tempfile.new('ticgit-ng-log-'))
- { :tic_dir => tempdir, :logger => logger }
+ { :tic_dir => tempdir, :logger => logger, :init => true }
end
View
13 spec/ticgit_spec.rb
@@ -15,6 +15,19 @@
Dir.glob(File.expand_path("/tmp/ticgit-ng-*")).each {|file_name| FileUtils.rm_r(file_name, {:force=>true,:secure=>true}) }
end
+ it "Should only create a new branch when 'ti init' is called" do
+ git_dir_2= setup_new_git_repo
+ git_opts_2= test_opts
+ git_opts_2[:init]=false
+
+ #With :init set to false, the default when calling ti
+ lambda { ticgitng_2=TicGitNG.open(git_dir_2, git_opts_2) }.should raise_error SystemExit
+
+ #with :init set to true, the default for TicGitNGSpecHelper.test_opts(), the branch should be created without error
+ lambda { ticgitng=TicGitNG.open( @path, @orig_test_opts )}.should_not raise_error SystemExit
+
+ end
+
it "should create a new branch if it's not there" do
br = @ticgitng.git.branches.map { |b| b.name }
br.should include('ticgit')

0 comments on commit 2ceb367

Please sign in to comment.