[ditz-talk] [PATCH] support searching up directory structure for root
Eric Merritt
cyberlync at gmail.com
Sat Apr 12 02:36:51 EDT 2008
This patch adds support for search up the directory structure for the bugs directory. In actually it looks up the directory structure for a <bugs-dir>/projects.yaml structure. When it finds that it uses that as the project root. This change has been enacted in every command except init.
---
bin/ditz | 22 +++++++++++++---------
lib/ditz.rb | 18 ++++++++++++++++++
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/bin/ditz b/bin/ditz
index ee52b15..7859e45 100755
--- a/bin/ditz
+++ b/bin/ditz
@@ -24,8 +24,9 @@ case cmd # some special cases not handled by Ditz::Operator
when "init"
die "#{dir} directory already exists" if File.exists? dir
FileUtils.mkdir dir
+ fn = File.join dir, PROJECT_FN
project = op.init
- project.save! dir
+ project.save! fn
puts "Ok, #{dir} directory created successfully."
exit
when "help"
@@ -33,14 +34,17 @@ when "help"
exit
end
-die "No #{dir} directory---use 'ditz init' to initialize" unless File.exists? dir
+project_root = Ditz::find_project_root dir, Dir.pwd
+
+die "No #{dir} directory---use 'ditz init' to initialize" unless project_root != nil and File.exists? project_root
+
project = begin
- fn = File.join dir, PROJECT_FN
+ fn = File.join project_root, PROJECT_FN
Ditz::debug "loading project from #{fn}"
project = Ditz::Project.from fn
- fn = File.join dir, "issue-*.yaml"
+ fn = File.join project_root, "issue-*.yaml"
Ditz::debug "loading issues from #{fn}"
project.issues = Dir[fn].map { |fn| Ditz::Issue.from fn }
Ditz::debug "found #{project.issues.size} issues"
@@ -87,7 +91,7 @@ end
## save project.yaml
dirty = project.each_modelobject { |o| break true if o.changed? } || false
if dirty
- fn = File.join dir, PROJECT_FN
+ fn = File.join project_root, PROJECT_FN
Ditz::debug "project is dirty, saving #{fn}"
project.each_modelobject { |o| o.before_serialize project }
project.save! fn
@@ -98,26 +102,26 @@ end
project.issues.each do |i|
if i.changed?
i.before_serialize project
- fn = File.join dir, ISSUE_TO_FN(i)
+ fn = File.join project_root, ISSUE_TO_FN(i)
Ditz::debug "issue #{i.name} is dirty, saving #{fn}"
i.save! fn
end
end
project.deleted_issues.each do |i|
- fn = File.join dir, ISSUE_TO_FN(i)
+ fn = File.join project_root, ISSUE_TO_FN(i)
Ditz::debug "issue #{i.name} has been deleted, deleting #{fn}"
FileUtils.rm fn
end
unless project.added_issues.empty?
puts "You may have to inform your SCM that the following files have been added:"
- project.added_issues.each { |i| puts " " + File.join(dir, ISSUE_TO_FN(i)) }
+ project.added_issues.each { |i| puts " " + File.join(project_root, ISSUE_TO_FN(i)) }
end
unless project.deleted_issues.empty?
puts "You may have to inform your SCM that the following files have been deleted:"
- project.deleted_issues.each { |i| puts " " + File.join(dir, ISSUE_TO_FN(i)) }
+ project.deleted_issues.each { |i| puts " " + File.join(project_root, ISSUE_TO_FN(i)) }
end
config.save! $opts[:config_file] if config.changed?
diff --git a/lib/ditz.rb b/lib/ditz.rb
index 7cab4a6..f3a6a30 100644
--- a/lib/ditz.rb
+++ b/lib/ditz.rb
@@ -1,3 +1,4 @@
+require 'pathname'
module Ditz
VERSION = "0.1.2"
@@ -7,6 +8,23 @@ def debug s
end
module_function :debug
+
+def find_project_root(dir, pwd)
+ p = Pathname.new pwd
+ np = p.join dir, "project.yaml"
+ if np.exist?
+ return np.dirname
+ else
+ if p.dirname != p
+ find_project_root dir, p.dirname
+ else
+ return nil
+ end
+ end
+end
+
+module_function :find_project_root
+
end
require 'model-objects'
--
1.5.4.4
More information about the ditz-talk
mailing list