Skip to content

Commit

Permalink
Allows default branch to be set to master on update
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg committed Feb 22, 2019
1 parent ff855e2 commit 9ba107d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
5 changes: 1 addition & 4 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
// Can only set `default_branch` on an already created repository with the target branches ref already in-place
if v, ok := d.GetOk("default_branch"); ok {
branch := v.(string)
// If branch is "master", and the repository hasn't been initialized yet, setting this value will fail
if branch != "master" {
repoReq.DefaultBranch = &branch
}
repoReq.DefaultBranch = &branch
}

repoName := d.Id()
Expand Down
43 changes: 43 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,26 @@ func TestAccGithubRepository_defaultBranch(t *testing.T) {
}),
),
},
{
Config: testAccGithubRepositoryUpdateConfigMasterDefaultBranch(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: "Updated " + description,
Homepage: "http://example.com/",
AutoInit: true,
HasIssues: true,
HasWiki: true,
AllowMergeCommit: true,
AllowSquashMerge: false,
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: false,
}),
),
},
},
})
}
Expand Down Expand Up @@ -718,6 +738,29 @@ resource "github_repository" "foo" {
`, randString, randString)
}

func testAccGithubRepositoryUpdateConfigMasterDefaultBranch(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
name = "tf-acc-test-%s"
description = "Updated Terraform acceptance tests %s"
homepage_url = "http://example.com/"
# So that acceptance tests can be run in a github organization
# with no billing
private = false
has_issues = true
has_wiki = true
allow_merge_commit = true
allow_squash_merge = false
allow_rebase_merge = false
has_downloads = true
auto_init = true
default_branch = "master"
}
`, randString, randString)
}

func testAccGithubRepositoryConfigTemplates(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
Expand Down

0 comments on commit 9ba107d

Please sign in to comment.