From d5c8337f1f684a2d116c1eab434cfd4f79cdecaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 21 Aug 2016 18:10:31 +0200 Subject: [PATCH] Fix `release` from detached HEAD Don't try to default `target_commitish` to the currently checked out branch. Instead, keep the value blank unless explicitly provided. It will default to the main branch on the server. --- commands/release.go | 14 ++++---------- commands/release_tpl.go | 2 +- features/release.feature | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/commands/release.go b/commands/release.go index 2304a2d4..2b0f5d80 100644 --- a/commands/release.go +++ b/commands/release.go @@ -73,7 +73,8 @@ With '--include-drafts', include draft releases in the listing. Further edit the contents of in a text editor before submitting. -c, --commitish - A SHA, tag, or branch name to attach the release to (default: current branch). + A commit SHA or branch name to attach the release to, only used if + doesn't already exist (default: main branch). The git tag name for this release. @@ -272,13 +273,6 @@ func createRelease(cmd *Command, args *Args) { gh := github.NewClient(project.Host) - commitish := flagReleaseCommitish - if commitish == "" { - currentBranch, err := localRepo.CurrentBranch() - utils.Check(err) - commitish = currentBranch.ShortName() - } - var title string var body string var editor *github.Editor @@ -290,7 +284,7 @@ func createRelease(cmd *Command, args *Args) { utils.Check(err) } else { cs := git.CommentChar() - message, err := renderReleaseTpl("Creating", cs, tagName, project.String(), commitish) + message, err := renderReleaseTpl("Creating", cs, tagName, project.String(), flagReleaseCommitish) utils.Check(err) editor, err := github.NewEditor("RELEASE", "release", message) @@ -306,7 +300,7 @@ func createRelease(cmd *Command, args *Args) { params := &github.Release{ TagName: tagName, - TargetCommitish: commitish, + TargetCommitish: flagReleaseCommitish, Name: title, Body: body, Draft: flagReleaseDraft, diff --git a/commands/release_tpl.go b/commands/release_tpl.go index cd6f3046..dee94026 100644 --- a/commands/release_tpl.go +++ b/commands/release_tpl.go @@ -6,7 +6,7 @@ import ( ) const releaseTmpl = ` -{{.CS}} {{.Operation}} release {{.TagName}} for {{.ProjectName}} from {{.BranchName}} +{{.CS}} {{.Operation}} release {{.TagName}} for {{.ProjectName}}{{if .BranchName}} from {{.BranchName}}{{end}} {{.CS}} {{.CS}} Write a message for this release. The first block of {{.CS}} text is the title and the rest is the description.` diff --git a/features/release.feature b/features/release.feature index c79fa2ac..7e8e4a86 100644 --- a/features/release.feature +++ b/features/release.feature @@ -181,7 +181,7 @@ MARKDOWN post('/repos/mislav/will_paginate/releases') { assert :draft => true, :tag_name => "v1.2.0", - :target_commitish => "master", + :target_commitish => "", :name => "will_paginate 1.2.0: Instant Gratification Monkey", :body => "" @@ -195,6 +195,23 @@ MARKDOWN https://github.com/mislav/will_paginate/releases/v1.2.0\n """ + Scenario: Create a release with target commitish + Given the GitHub API server: + """ + post('/repos/mislav/will_paginate/releases') { + assert :tag_name => "v1.2.0", + :target_commitish => "my-branch" + + status 201 + json :html_url => "https://github.com/mislav/will_paginate/releases/v1.2.0" + } + """ + When I successfully run `hub release create -m hello v1.2.0 -c my-branch` + Then the output should contain exactly: + """ + https://github.com/mislav/will_paginate/releases/v1.2.0\n + """ + Scenario: Create a release with assets Given the GitHub API server: """