lib/depl/main.rb in depl-0.0.4 vs lib/depl/main.rb in depl-0.0.5

- old
+ new

@@ -21,65 +21,80 @@ def prefix @config[:prefix] || "deploy-" end + def origin + @config[:origin] || "origin" + end + def deploy_branch - "#{prefix}#{environment}" + [prefix, environment].join('') end - def save_sha - execute("git push --force origin #{local_sha}:refs/heads/#{deploy_branch}") + def tag_name + date = Time.now.strftime('%Y-%m-%d-%H-%M-%S') + [prefix, environment, '-', date].join('') end + def tag_release + execute("git tag -a '#{tag_name}' #{local_sha}") + end + + def advance_branch_pointer + execute("git push --follow-tags --force #{origin} #{local_sha}:refs/heads/#{deploy_branch}") + end + def run! if @config['before_hook'] `#{@config['before_hook']}` end - save_sha + tag_release + advance_branch_pointer if @config['after_hook'] `#{@config['after_hook']}` end end def remote_sha - `git fetch origin` - sha = execute("git rev-parse -q --verify origin/#{deploy_branch}").chomp - sha if sha != "" + `git fetch #{origin}` + sha = execute("git rev-parse -q --verify #{origin}/#{deploy_branch}") + sha && sha.chomp || raise("missing remote sha for #{origin}/#{deploy_branch}") end - def up_to_date + def up_to_date? local_sha == remote_sha end def local_sha rev = @options[:rev] || @config[:branch] || 'head' - sha = execute("git rev-parse -q --verify #{rev}").chomp - sha if sha != "" + sha = execute("git rev-parse -q --verify #{rev}") + sha && sha.chomp || raise("missing local sha: #{rev}") end def diff - execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{remote_sha}..#{local_sha}" + execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{remote_sha}..#{local_sha}" end def reverse_diff - execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{local_sha}..#{remote_sha}" + execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{local_sha}..#{remote_sha}" end def older_local_sha return false unless remote_sha - execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") && $?.exitstatus == 0 + !!execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") end def commit_count diff.split("\n").size end protected def execute(cmd) - `#{cmd}` + output = `#{cmd}` + $?.exitstatus == 0 && output end end end