summaryrefslogtreecommitdiff
path: root/lib/pgxn_utils
diff options
context:
space:
mode:
authorDickson S. Guedes2011-10-12 22:35:19 +0000
committerDickson S. Guedes2011-10-12 22:35:19 +0000
commit91ae5ef24352af905d6c8d530fbfaa28e1e15426 (patch)
tree66440e87fe9cb7a60d6c6a9d6113292218516a97 /lib/pgxn_utils
parentda852cd006cfd841fddb78fb363a0c3fb315dfe2 (diff)
parentef10e820f22f190a2a16dfc06b15a7b6f645b7d4 (diff)
Merge pull request #23 from guedes/git-supportHEADmaster
Added git support.
Diffstat (limited to 'lib/pgxn_utils')
-rw-r--r--lib/pgxn_utils/cli.rb45
-rw-r--r--lib/pgxn_utils/no_tasks.rb48
-rw-r--r--lib/pgxn_utils/templates/root/.gitignore.tt8
3 files changed, 84 insertions, 17 deletions
diff --git a/lib/pgxn_utils/cli.rb b/lib/pgxn_utils/cli.rb
index fc22c1d..cbec0ee 100644
--- a/lib/pgxn_utils/cli.rb
+++ b/lib/pgxn_utils/cli.rb
@@ -23,20 +23,22 @@ module PgxnUtils
method_option :generated_by, :aliases => "-b", :type => :string, :desc => "Name of extension's generator"
method_option :tags, :aliases => "-t", :type => :array, :desc => "Defines extension's tags"
method_option :release_status, :aliases => "-r", :type => :string, :desc => "Initial extension's release status"
+ method_option :git, :type => :boolean, :default => false, :desc => "Initialize a git repository after create the extension"
def skeleton(extension_name,target=nil)
self.target = options[:target] || target || "."
if is_extension?("#{self.target}/#{extension_name}")
say "'#{extension_name}' already exists. Please, use 'change' instead 'skeleton'.", :red
- elsif is_extension?(".")
+ elsif is_extension?(self.target)
say "You are inside a extension directory, already. Consider use 'change' instead.", :red
elsif is_dir?("#{self.target}/#{extension_name}")
say "Can't create an extension overwriting an existing directory.", :red
else
self.set_accessors extension_name
-
directory "root", extension_name
+
+ init_repository("#{self.target}/#{extension_name}") if options[:git]
end
end
@@ -83,21 +85,30 @@ module PgxnUtils
self.target = path
archive_name = "#{path}-#{config_options['version']}"
- ext = "zip"
- archive = "#{archive_name}.#{ext}"
-
- if can_zip?(archive)
- make_dist_clean(path)
-
- Zippy.create(archive) do |zip|
- Dir["#{path}/**/**"].each do |file|
- zip["#{extension_name}-#{config_options['version']}/#{file.sub(path+'/','')}"] = File.open(file) unless File.directory?(file)
- end
- end
- say_status :create, archive, :green
- end
- end
- end
+ prefix_name = "#{extension_name}-#{config_options['version']}/"
+
+ archive = "#{archive_name}.zip"
+ archived = false
+
+ if has_scm?(path)
+ if is_dirty?(path)
+ say "Your repository is dirty! You should commit or stash before continue.", :red
+ else
+ if can_zip?(archive)
+ scm_archive(path, archive, prefix_name)
+ archived = true
+ end
+ end
+ else
+ if can_zip?(archive)
+ make_dist_clean(path)
+ zip_archive(path, archive, prefix_name)
+ archived = true
+ end
+ end
+ say_status(:create, archive, :green) if archived
+ end
+ end
desc "release filename", "Release an extension to PGXN"
diff --git a/lib/pgxn_utils/no_tasks.rb b/lib/pgxn_utils/no_tasks.rb
index a066998..9dc62ad 100644
--- a/lib/pgxn_utils/no_tasks.rb
+++ b/lib/pgxn_utils/no_tasks.rb
@@ -2,6 +2,33 @@ module PgxnUtils
module NoTasks
include PgxnUtils::Constants
+ include Grit
+
+ def init_repository(extension_dir)
+ repo = Repo.init(extension_dir)
+ original_dir = File.expand_path "."
+
+ if repo
+ say_status :init, "#{extension_dir}", :green
+
+ FileUtils.chdir extension_dir
+ repo.add "."
+ if repo.commit_index("initial commit")
+ say_status :commit, "initial commit", :green
+ else
+ say_status :failed, "initial commit", :red
+ end
+ else
+ say_status :error, " initializing #{extension_dir}", :red
+ end
+
+ FileUtils.chdir original_dir
+ end
+
+ def is_dirty?(extension_dir)
+ repo = Repo.init(extension_dir)
+ repo.status.map(&:type).uniq != [nil]
+ end
def make_dist_clean(path)
inside path do
@@ -77,6 +104,27 @@ module PgxnUtils
[ extension_path, extension_name ]
end
+ def has_scm?(path)
+ begin
+ Repo.new(path)
+ rescue Grit::InvalidGitRepositoryError
+ false
+ end
+ end
+
+ def scm_archive(path, archive, prefix, treeish='master')
+ git = Git.new(Repo.new(path).path)
+ git.archive({:format => "zip", :prefix => prefix, :output => archive}, treeish)
+ end
+
+ def zip_archive(path, archive, prefix)
+ Zippy.create(archive) do |zip|
+ Dir["#{path}/**/**"].each do |file|
+ zip["#{prefix}#{file.sub(path+'/','')}"] = File.open(file) unless File.directory?(file)
+ end
+ end
+ end
+
def can_zip?(archive)
can_zip = false
diff --git a/lib/pgxn_utils/templates/root/.gitignore.tt b/lib/pgxn_utils/templates/root/.gitignore.tt
new file mode 100644
index 0000000..7ccbc9d
--- /dev/null
+++ b/lib/pgxn_utils/templates/root/.gitignore.tt
@@ -0,0 +1,8 @@
+results/
+*.so
+tmp/
+*.o
+regression.diffs
+regression.out
+/sql/<%= extension_name =>--*
+!/sql/<%= extension_name =>--*--*.sql