Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

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
fmasuhr committed Jun 22, 2020
1 parent 950c0f1 commit 5694e6b
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 @@ -348,10 +348,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 @@ -321,6 +321,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,
}),
),
},
{
ResourceName: rn,
ImportState: true,
Expand Down Expand Up @@ -859,6 +879,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 5694e6b

Please sign in to comment.