From 9ec50ee7556539e903ca3ee076d5ba07fdf0c5be Mon Sep 17 00:00:00 2001 From: Dickson S. Guedes Date: Thu, 6 Oct 2011 22:49:47 -0300 Subject: adding git support, ref #16 Added more example to README Now pgxn_utils notice the repository creation Now pgxn_utils do an initial commit --- Rakefile | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index ba4e00d..bf9b0a6 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' def format_cmd_output(cmd) - `./bin/pgxn_utils #{cmd} | sed 's/^/ /' | sed 's/\[[0-9]*m//g'` + `./bin/pgxn-utils #{cmd} | sed 's/^/ /' | sed 's/\[[0-9]*m//g'` end desc "Run RSpec" @@ -22,6 +22,7 @@ end desc "Generate README.md" task :generate_readme do rm_r "/tmp/my_cool_extension" if File.exist?("/tmp/my_cool_extension") + rm_r "/tmp/my_cool_versioned_extension" if File.exist?("/tmp/my_cool_versioned_extension") readme = File.new("README.md.new", 'w') readme.puts <<-README pgxn utils @@ -30,40 +31,53 @@ pgxn utils What is it? -------- -It aims to be a set of task to help PostgreSQL extension's developers to focus more on the problem that they wants to solve than in the all structure and files and control files need to PGXS to build the extension. +It aims to be a set of task to help PostgreSQL extension's developers to focus more on the problem that they wants to solve than in all structure and files and control files need to PGXS to build the extension. How to install it? ------------------ +If you have pgxn client installed you can do: + + pgxn install pgxn_utils + +Or you can install it by rubygems: + gem install pgxn_utils How it works? ------------- -It is all about tasks. Let's see what tasks we have: +It is all about tasks. Let's see them: - $ pgxn_utils help + $ pgxn-utils help #{format_cmd_output("help")} # Creating a new extension - $ pgxn_utils skeleton my_cool_extension + $ pgxn-utils skeleton my_cool_extension #{format_cmd_output("skeleton my_cool_extension -p /tmp")} +You can start creating an extension with or without version control. By default `pgxn-utils` +supports (git)[http://git-scm.org] but it will not create a repository unless you use `--git` +option in the skeleton task. + + $ pgxn-utils skeleton my_cool_versioned_extension --git +#{format_cmd_output("skeleton my_cool_versioned_extension --git -p /tmp")} + Thats it! Just start coding! ":) # Changing something -Well suppose you want to change the default maintainer's name and the license, well just do: +Well suppose you want to change the default maintainer's name and the license, just do: - $ pgxn_utils change my_cool_extension --maintainer "Dickson Guedes" --license bsd + $ pgxn-utils change my_cool_extension --maintainer "Dickson Guedes" --license bsd #{format_cmd_output("change my_cool_extension -p /tmp --maintainer 'Dickson Guedes' --license bsd")} It will wait you decide what to do. For all switches that you can use with *change*, type: - $ pgxn_utils help change + $ pgxn-utils help change #{format_cmd_output("help change")} # Bundling and Releasing! @@ -72,12 +86,12 @@ Well, since you finished your work you can bundle it to send to [PGXN](http://pg Bundle it: - $ pgxn_utils bundle my_cool_extension + $ pgxn-utils bundle my_cool_extension Extension generated at: /home/guedes/extensions/my_cool_extension-0.0.1.zip and release it: - $ pgxn_utils release my_cool_extension-0.0.1.zip + $ pgxn-utils release my_cool_extension-0.0.1.zip Enter your PGXN username: guedes Enter your PGXN password: ****** Trying to release my_cool_extension-0.0.1.zip ... released successfully! -- cgit v1.2.3 From 0571ae04b1425ceea1b893e42a783c365cb801ae Mon Sep 17 00:00:00 2001 From: Dickson S. Guedes Date: Wed, 12 Oct 2011 14:57:00 -0300 Subject: bundle using git archive, ref #17 --- README.md | 17 +++++++++++++++-- Rakefile | 17 +++++++++++++++-- lib/pgxn_utils/cli.rb | 39 ++++++++++++++++++++++++--------------- lib/pgxn_utils/no_tasks.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 19 deletions(-) (limited to 'Rakefile') diff --git a/README.md b/README.md index b8168ae..2aaa9bb 100644 --- a/README.md +++ b/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 diff --git a/Rakefile b/Rakefile index bf9b0a6..d1501c4 100644 --- a/Rakefile +++ b/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 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 -- cgit v1.2.3 From eb2af742a0b483b4587ed1c591a06740652885ae Mon Sep 17 00:00:00 2001 From: Dickson S. Guedes Date: Wed, 12 Oct 2011 15:00:43 -0300 Subject: fixing git url on README, ref #17 --- README.md | 2 +- Rakefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Rakefile') diff --git a/README.md b/README.md index 2aaa9bb..df911d0 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ It is all about tasks. Let's see them: create my_cool_extension/test/sql/base.sql You can start creating an extension with or without version control. By default `pgxn-utils` -supports (git)[http://git-scm.org] but it will not create a repository unless you use `--git` +supports [git](http://git-scm.org) but it will not create a repository unless you use `--git` option in the skeleton task. $ pgxn-utils skeleton my_cool_versioned_extension --git diff --git a/Rakefile b/Rakefile index d1501c4..f373afd 100644 --- a/Rakefile +++ b/Rakefile @@ -58,7 +58,7 @@ It is all about tasks. Let's see them: #{format_cmd_output("skeleton my_cool_extension -p /tmp")} You can start creating an extension with or without version control. By default `pgxn-utils` -supports (git)[http://git-scm.org] but it will not create a repository unless you use `--git` +supports [git](http://git-scm.org) but it will not create a repository unless you use `--git` option in the skeleton task. $ pgxn-utils skeleton my_cool_versioned_extension --git -- cgit v1.2.3 From ef10e820f22f190a2a16dfc06b15a7b6f645b7d4 Mon Sep 17 00:00:00 2001 From: Dickson S. Guedes Date: Wed, 12 Oct 2011 15:16:06 -0300 Subject: fixing git url on README, ref #17 --- README.md | 4 ++-- Rakefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'Rakefile') diff --git a/README.md b/README.md index df911d0..782a02d 100644 --- a/README.md +++ b/README.md @@ -157,8 +157,8 @@ 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` +Once you have your extension in a git repository your `bundle` will use only the +commited files to create the archive, but if your repository is dirty then `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 diff --git a/Rakefile b/Rakefile index f373afd..67f775a 100644 --- a/Rakefile +++ b/Rakefile @@ -106,8 +106,8 @@ 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` +Once you have your extension in a git repository your `bundle` will use only the +commited files to create the archive, but if your repository is dirty then `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 -- cgit v1.2.3