Permalink
Browse files

bundle using git archive, ref #17

  • Loading branch information...
1 parent 0428c2f commit 0571ae04b1425ceea1b893e42a783c365cb801ae @guedes guedes committed Oct 12, 2011
Showing with 80 additions and 19 deletions.
  1. +15 −2 README.md
  2. +15 −2 Rakefile
  3. +24 −15 lib/pgxn_utils/cli.rb
  4. +26 −0 lib/pgxn_utils/no_tasks.rb
View
17 README.md
@@ -138,7 +138,7 @@ Well, since you finished your work you can bundle it to send to [PGXN](http://pg
Bundle it:
$ pgxn-utils bundle my_cool_extension
- Extension generated at: /home/guedes/extensions/my_cool_extension-0.0.1.zip
+ create /home/guedes/extensions/my_cool_extension-0.0.1.zip
and release it:
@@ -151,9 +151,22 @@ and release it:
You can export `PGXN_USER` and `PGXN_PASSWORD` environment variables to avoid
type username and password everytime.
+# Git support
+
+You can start a new extension with git support calling `skeleton` task with
+`--git` flag, then in addition to create skeleton, `pgxn-utils` will initialize
+a git repository and do a initial commit.
+
+Once you have you extension in a git repository your `bundle` will use only the
+commited files to create the archive, but if your repository is dirty `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
+
+You must be careful with new files not added to repository, because they will NOT
+be archived.
+
# Working in progress
-* [git](http://git-scm.org) support
+* improve [git](http://git-scm.org) support
* proxy support
* custom templates
View
17 Rakefile
@@ -87,7 +87,7 @@ Well, since you finished your work you can bundle it to send to [PGXN](http://pg
Bundle it:
$ pgxn-utils bundle my_cool_extension
- Extension generated at: /home/guedes/extensions/my_cool_extension-0.0.1.zip
+ create /home/guedes/extensions/my_cool_extension-0.0.1.zip
and release it:
@@ -100,9 +100,22 @@ and release it:
You can export `PGXN_USER` and `PGXN_PASSWORD` environment variables to avoid
type username and password everytime.
+# Git support
+
+You can start a new extension with git support calling `skeleton` task with
+`--git` flag, then in addition to create skeleton, `pgxn-utils` will initialize
+a git repository and do a initial commit.
+
+Once you have you extension in a git repository your `bundle` will use only the
+commited files to create the archive, but if your repository is dirty `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
+
+You must be careful with new files not added to repository, because they will NOT
+be archived.
+
# Working in progress
-* [git](http://git-scm.org) support
+* improve [git](http://git-scm.org) support
* proxy support
* custom templates
View
39 lib/pgxn_utils/cli.rb
@@ -85,21 +85,30 @@ def bundle(extension_name=".")
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"
View
26 lib/pgxn_utils/no_tasks.rb
@@ -25,6 +25,11 @@ def init_repository(extension_dir)
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
run 'make distclean', :capture => true
@@ -99,6 +104,27 @@ def resolve_extension_path_and_name(extension_name)
[ 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

0 comments on commit 0571ae0

Please sign in to comment.