diff options
author | Dickson S. Guedes | 2011-10-12 17:57:00 +0000 |
---|---|---|
committer | Dickson S. Guedes | 2011-10-12 17:57:00 +0000 |
commit | 0571ae04b1425ceea1b893e42a783c365cb801ae (patch) | |
tree | b114dc5ffeafaaba660d50b3014b0aadea80e5fb | |
parent | 0428c2fb77d2daa2bce07916fe41691c2125653d (diff) |
bundle using git archive, ref #17
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | Rakefile | 17 | ||||
-rw-r--r-- | lib/pgxn_utils/cli.rb | 39 | ||||
-rw-r--r-- | lib/pgxn_utils/no_tasks.rb | 26 |
4 files changed, 80 insertions, 19 deletions
@@ -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 @@ -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 diff --git a/lib/pgxn_utils/cli.rb b/lib/pgxn_utils/cli.rb index 65e0487..cbec0ee 100644 --- a/lib/pgxn_utils/cli.rb +++ b/lib/pgxn_utils/cli.rb @@ -85,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 abbd455..9dc62ad 100644 --- a/lib/pgxn_utils/no_tasks.rb +++ b/lib/pgxn_utils/no_tasks.rb @@ -25,6 +25,11 @@ module PgxnUtils 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 @@ 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 |