TicGit-ng 1.0.2.11 → 1.0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,19 @@ module TicGitNG
10
10
 
11
11
  def initialize(git_dir, opts = {})
12
12
  @git = Git.open(find_repo(git_dir))
13
+ @logger = opts[:logger] || Logger.new(STDOUT)
14
+
15
+ #This is to accomodate for edge-cases where @logger.puts
16
+ #is called from debugging code.
17
+ unless @logger.respond_to?(:puts)
18
+ def @logger.puts str
19
+ self.info str
20
+ end
21
+ end
22
+
23
+ @last_tickets = []
24
+ @init=opts[:init]
25
+
13
26
  proj = Ticket.clean_string(@git.dir.path)
14
27
 
15
28
  @tic_dir = opts[:tic_dir] || "~/.#{which_branch?}"
@@ -19,15 +32,23 @@ module TicGitNG
19
32
  @logger = opts[:logger] || Logger.new(STDOUT)
20
33
  @last_tickets = []
21
34
 
22
- #expire @tic_index and @tic_working if it mtime is older than git log
35
+ #expire @tic_index and @tic_working if it mtime is older than
36
+ #git log. Otherwise, during testing, if you use the same temp
37
+ #directory with the same name, deleting it and recreating it
38
+ #to test something, ticgit would get confused by the cache from
39
+ #the previous instance of the temp dir.
23
40
  if File.exist?(@tic_working)
24
41
  cache_mtime=File.mtime(@tic_working)
25
- gitlog_mtime=git.gblob(which_branch?).log(1).map {|l| l.committer.date }[0]
42
+ (gitlog_mtime=git.gblob(which_branch?).log(1).map {|l| l.committer.date }[0]) rescue reset_cache
43
+
26
44
  #unless (cache_mtime > gitlog_mtime.-(20) and cache_mtime <= gitlog_mtime) or (cache_mtime > gitlog_mtime.+(30) and cache_mtime >= gitlog_mtime)
27
- if ((cache_mtime.to_i - gitlog_mtime.to_i) > 120) or ((gitlog_mtime.to_i - cache_mtime.to_i) > 120)
28
- puts "Resetting cache"
29
- reset_cache unless cache_mtime==gitlog_mtime
45
+ #FIXME break logic out into several lines
46
+ #FIXME don't bother resetting if gitlog_mtime.to_i == 0
47
+ if needs_reset?( cache_mtime, gitlog_mtime ) and !cache_mtime==gitlog_mtime
48
+ puts "Resetting cache" unless gitlog_mtime.to_i == 0
49
+ reset_cache
30
50
  end
51
+
31
52
  end
32
53
 
33
54
  # load config file
@@ -313,7 +334,15 @@ module TicGitNG
313
334
 
314
335
  unless (bs.include?(which_branch?) || bs.include?(which_branch?)) &&
315
336
  File.directory?(@tic_working)
316
- init_ticgitng_branch(bs.include?(which_branch?))
337
+ unless @init
338
+ puts "Please run `ti init` to initialize TicGit-ng for this repository before running other ti commands."
339
+ exit
340
+ else
341
+ puts "Initializing TicGit-ng"
342
+ init_ticgitng_branch(
343
+ git.lib.branches_all.map{|b| b.first }.include?(which_branch?)
344
+ )
345
+ end
317
346
  end
318
347
 
319
348
  tree = git.lib.full_tree(which_branch?)
@@ -331,7 +360,7 @@ module TicGitNG
331
360
  end
332
361
 
333
362
  def init_ticgitng_branch(ticgitng_branch = false)
334
- @logger.info 'creating ticgit-ng repo branch'
363
+ @logger << 'creating ticgit-ng repo branch'
335
364
 
336
365
  in_branch(ticgitng_branch) do
337
366
  #The .hold file seems to have little to no purpose aside from helping
@@ -390,11 +419,18 @@ module TicGitNG
390
419
 
391
420
  def reset_cache
392
421
  #@state, @tic_index, @tic_working
422
+ #A rescue is appended to the end of each line because it allows
423
+ #execution of others to continue upon failure, as opposed to
424
+ #a begin;rescue;end segment.
425
+ FileUtils.rm_r File.expand_path(@tic_working) rescue nil
393
426
  FileUtils.rm File.expand_path(@state) rescue nil
394
427
  FileUtils.rm File.expand_path(@tic_index) rescue nil
395
- FileUtils.rm_r File.expand_path(@tic_working) rescue nil
428
+ FileUtils.mkdir_p File.expand_path(@tic_working) rescue nil
396
429
  @state=nil
397
- FileUtils.mkdir_p File.expand_path(@tic_working)
430
+ end
431
+
432
+ def needs_reset? cache_mtime, gitlog_mtime
433
+ ((cache_mtime.to_i - gitlog_mtime.to_i) > 120) or ((gitlog_mtime.to_i - cache_mtime.to_i) > 120)
398
434
  end
399
435
 
400
436
  end
data/lib/ticgit-ng/cli.rb CHANGED
@@ -21,13 +21,23 @@ module TicGitNG
21
21
 
22
22
  def initialize(args, path = '.', out = $stdout)
23
23
  @args = args.dup
24
- @tic = TicGitNG.open(path, :keep_state => true)
24
+
25
+ #set @init if one of the args is 'init'
26
+ #this needs to be done because initialization of the ticgit branch must be done before
27
+ #the branch is loaded, but because of the way commands are modularized this must be done
28
+ #outside of and before the init.rb file itself is called (init.rb is where we would
29
+ #normally put the code for such a command).
30
+ args.include?( 'init' ) ? (@init=true) : (@init=false)
31
+ #@init= ((args[0][/init/]=='init') rescue false)
32
+ #@init= ((args[0][/init/]=='init') or (args[1][/init/]=='init') rescue false)
33
+
34
+ @tic = TicGitNG.open(path, {:keep_state => true, :init => @init, :logger => out })
25
35
  @options = OpenStruct.new
26
36
  @out = out
27
37
 
28
38
  @out.sync = true # so that Net::SSH prompts show up
29
39
  rescue NoRepoFound
30
- puts "No repo found"
40
+ out.puts "No repo found"
31
41
  exit
32
42
  end
33
43
 
@@ -64,7 +74,13 @@ module TicGitNG
64
74
  exit 1
65
75
  end
66
76
 
67
- @action = args.shift
77
+ #FIXME
78
+ #this is a dirty hack that needs to be fixed
79
+ if args.include?('list') and args.include?('init')
80
+ @action = 'list'
81
+ else
82
+ @action = args.shift
83
+ end
68
84
  end
69
85
 
70
86
  def usage(args = nil)
@@ -10,7 +10,8 @@ module TicGitNG
10
10
  # ti assign -u {name} {1} (assign specified ticket to specified user)
11
11
  module Assign
12
12
  def parser(opts)
13
- opts.banner = "Usage: ti assign [options] [ticket_id]"
13
+ opts.banner = "Usage: ti assign [options] [ticket_id]\n"+
14
+ "Note: to assign to nobody: ti assign -u ''"
14
15
  opts.on_head(
15
16
  "-u USER", "--user USER", "Assign the ticket to this user"){|v|
16
17
  options.user = v
@@ -0,0 +1,20 @@
1
+ module TicGitNG
2
+ module Command
3
+ module Init
4
+ def parser o
5
+ o.banner= "Usage: ti init"
6
+ end
7
+ def execute
8
+ @tic.read_tickets
9
+ =begin
10
+ #Initialization has to happen earlier in the code so this code stands
11
+ #as an example, when `ti init` is called, initialization is handled by
12
+ #base.rb:354 (at the time of writing this).
13
+ tic.base.init_ticgitng_branch(
14
+ git.lib.branches_all.map{|b| b.first }.include?(which_branch?)
15
+ )
16
+ =end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -22,6 +22,7 @@ module TicGitNG
22
22
  register 'State', 'Change state of a ticket', 'state'
23
23
  register 'Tag', 'Modify tags of a ticket', 'tag'
24
24
  register 'Sync', 'Sync tickets', 'sync'
25
+ register 'Init', 'Initialize Ticgit-ng', 'init'
25
26
 
26
27
  def self.get(command)
27
28
  if mod_name = COMMANDS[command]
@@ -1,3 +1,3 @@
1
1
  module TicGitNG
2
- VERSION = '1.0.2.11'
2
+ VERSION = '1.0.2.12'
3
3
  end
data/lib/ticgit-ng.rb CHANGED
@@ -41,7 +41,11 @@ module TicGitNG
41
41
  autoload :Ticket, 'ticgit-ng/ticket'
42
42
 
43
43
  # options
44
- # :logger => Logger.new(STDOUT)
44
+ # :logger => Logger.new(STDOUT)
45
+ # :tic_dir => "~/.#{ which_branch?() }"
46
+ # :working_directory => File.expand_path(File.join(@tic_dir, proj, 'working'))
47
+ # :index_file => File.expand_path(File.join(@tic_dir, proj, 'index'))
48
+ # :init => Boolean -- if true, allow initializing ticgit
45
49
  def self.open(git_dir, options = {})
46
50
  Base.new(git_dir, options)
47
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TicGit-ng
3
3
  version: !ruby/object:Gem::Version
4
- hash: 65
4
+ hash: 79
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 2
10
- - 11
11
- version: 1.0.2.11
10
+ - 12
11
+ version: 1.0.2.12
12
12
  platform: ruby
13
13
  authors:
14
14
  - Scott Chacon
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-11-09 00:00:00 -08:00
20
+ date: 2012-01-04 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,7 @@ files:
72
72
  - lib/ticgit-ng/command/tag.rb
73
73
  - lib/ticgit-ng/command/recent.rb
74
74
  - lib/ticgit-ng/command/sync.rb
75
+ - lib/ticgit-ng/command/init.rb
75
76
  - lib/ticgit-ng/command/assign.rb
76
77
  - lib/ticgit-ng/command/list.rb
77
78
  - lib/ticgit-ng/command/milestone.rb