Skip to content

Commit

Permalink
Use -R [REF] or --force-ref [REF] to override the default branch.
Browse files Browse the repository at this point in the history
Specifying --ignore-default-branch, --force-ref or -R without arguments still works like before.
  • Loading branch information
martinemde committed Dec 14, 2011
1 parent c0495ed commit b8983de
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Expand Up @@ -2,7 +2,7 @@

## NEXT

*
* Use -R [REF] or --force-ref [REF] to override the default branch. Specifying --ignore-default-branch, --force-ref or -R without arguments still works like before.

## v1.4.14 (2011-12-13)

Expand Down
13 changes: 7 additions & 6 deletions lib/engineyard/cli.rb
Expand Up @@ -30,8 +30,9 @@ def self.start(*)
command can be specified via --migrate "ruby do_migrations.rb". Migrations
can also be skipped entirely by using --no-migrate.
DESC
method_option :ignore_default_branch, :type => :boolean,
:desc => "Force a deploy of the specified branch even if a default is set"
method_option :force_ref, :type => :string, :aliases => %w(--ignore-default-branch -R),
:lazy_default => true,
:desc => "Force a deploy of the specified git ref even if a default is set in ey.yml."
method_option :ignore_bad_master, :type => :boolean,
:desc => "Force a deploy even if the master is in a bad state"
method_option :migrate, :type => :string, :aliases => %w(-m),
Expand All @@ -40,7 +41,7 @@ def self.start(*)
method_option :environment, :type => :string, :aliases => %w(-e),
:desc => "Environment in which to deploy this application"
method_option :ref, :type => :string, :aliases => %w(-r --branch --tag),
:desc => "Git ref to deploy. May be a branch, a tag, or a SHA."
:desc => "Git ref to deploy. May be a branch, a tag, or a SHA. Use -R to deploy a different ref if a default is set."
method_option :app, :type => :string, :aliases => %w(-a),
:desc => "Name of the application to deploy"
method_option :account, :type => :string, :aliases => %w(-c),
Expand All @@ -55,10 +56,10 @@ def deploy
app, environment = fetch_app_and_environment(options[:app], options[:environment], options[:account])
environment.ignore_bad_master = options[:ignore_bad_master]
deploy_ref = if options[:app]
environment.resolve_branch(options[:ref], options[:ignore_default_branch]) ||
environment.resolve_branch(options[:ref], options[:force_ref]) ||
raise(EY::Error, "When specifying the application, you must also specify the ref to deploy\nUsage: ey deploy --app <app name> --ref <branch|tag|ref>")
else
environment.resolve_branch(options[:ref], options[:ignore_default_branch]) ||
environment.resolve_branch(options[:ref], options[:force_ref]) ||
repo.current_branch ||
raise(DeployArgumentError)
end
Expand Down Expand Up @@ -342,7 +343,7 @@ def help(*cmds)

desc "launch [--environment ENVIRONMENT] [--account ACCOUNT]", "Open application in browser."
method_option :environment, :type => :string, :aliases => %w(-e),
:desc => "Environment with the interesting logs"
:desc => "Name of the environment"
method_option :account, :type => :string, :aliases => %w(-c),
:desc => "Name of the account in which the environment can be found"
def launch
Expand Down
16 changes: 12 additions & 4 deletions lib/engineyard/model/environment.rb
Expand Up @@ -115,11 +115,19 @@ def upload_recipes(file_to_upload)
})
end

def resolve_branch(branch, allow_non_default_branch=false)
if !allow_non_default_branch && branch && default_branch && (branch != default_branch)
raise BranchMismatchError.new(default_branch, branch)
# If force_ref is a string, use it as the ref, otherwise use it as a boolean.
def resolve_branch(ref, force_ref=false)
if String === force_ref
ref, force_ref = force_ref, true
end

if !ref
default_branch
elsif force_ref || !default_branch || ref == default_branch
ref
else
raise BranchMismatchError.new(default_branch, ref)
end
branch || default_branch
end

def configuration
Expand Down
7 changes: 6 additions & 1 deletion spec/ey/deploy_spec.rb
Expand Up @@ -264,7 +264,7 @@ def verify_ran(scenario)
@ssh_commands.last.should =~ /--ref resolved-master/
end

it "complains about a non-default branch without --ignore-default_branch" do
it "complains about a non-default branch without --ignore-default-branch" do
fast_failing_ey %w[deploy -r current-branch]
@err.should =~ /deploy branch is set to "master"/
end
Expand All @@ -273,6 +273,11 @@ def verify_ran(scenario)
fast_ey %w[deploy -r current-branch --ignore-default-branch]
@ssh_commands.last.should =~ /--ref resolved-current-branch/
end

it "deploys a non-default branch with --R ref" do
fast_ey %w[deploy -R current-branch]
@ssh_commands.last.should =~ /--ref resolved-current-branch/
end
end
end

Expand Down

0 comments on commit b8983de

Please sign in to comment.