Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the default_branch as the name of an initialized branch instead of defaulting to master #89

Merged
merged 5 commits into from
Jul 22, 2020

Conversation

jamiemccrindle
Copy link

@jamiemccrindle jamiemccrindle commented Jul 19, 2020

All Submissions:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code follows the code style of this project.
  • I ran lint checks locally prior to submission.
  • Have you checked to ensure there aren't other open PRs for the same update/change?

What about the current behavior has changed?

Currently if you initialize a repo, it will always create a 'master' branch. If you specify a 'default_branch' that isn't master, setting the default branch will fail. This change means that the value of 'default_branch' is used as the branch name on initialization e.g. if you wanted the branch to be called 'refs/heads/main'. Note: this only changes the behaviour for 'Clean' initialization type. For uninitialized, there won't be a branch to set.

Issue Number: No issue

Does this introduce a change to go.mod, go.sum or vendor/?

  • No

Does this introduce a breaking change?

  • No

This does change the behavior in that 'default_branch' now works when initializing repos where previously it didn't.

Any relevant logs, error output, etc?

n/a

Other information

No component changes.

@xuzhang3 xuzhang3 self-assigned this Jul 20, 2020
@xuzhang3
Copy link
Collaborator

Hi @jamiemccrindle Thanks for opening this PR. I try update the repository default_branch and I will get an error :
image
Because the branch I try set as default branch does not exist.

@jamiemccrindle
Copy link
Author

jamiemccrindle commented Jul 20, 2020 via email

@ghost ghost removed the waiting-response label Jul 20, 2020
@xuzhang3
Copy link
Collaborator

@jamiemccrindle
Reproduce steps:

  1. terraform apply
  2. change default_branch to another branch like refs/heads/release
  3. terraform apply

TF config:

resource "azuredevops_project" "project" {
  project_name       = "Sample Project"
  visibility         = "private"
  version_control    = "Git"
  work_item_template = "Agile"
}

resource "azuredevops_git_repository" "repo" {
  project_id = azuredevops_project.project.id
  name       = "Sample Empty Git Repository"
  initialization {
    init_type = "Clean"
  }
  default_branch="refs/heads/master"
}

@jamiemccrindle
Copy link
Author

Thank you!

Testing now. I suspect that this may have broken before too i.e. the initalization only happens once and the default branch needs the branch to exist but will confirm.

@xuzhang3
Copy link
Collaborator

Set default_branch attribute ForceNew: true, might be a choice for this issue. A new repo will be created and destroy the old one .

@jamiemccrindle
Copy link
Author

@xuzhang3, have confirmed that this would also break in trunk i.e. changing the default branch after creation to a branch that doesn't exist. If adding force_new it useful it might be better to add it in another PR.

@EliiseS
Copy link
Member

EliiseS commented Jul 20, 2020

@xuzhang3 @jamiemccrindle Could one of you create an issue for the bug you discovered? 😛

@jamiemccrindle
Copy link
Author

hi @EliiseS, is it the one for a change of the default_branch setting failing on update if the branch doesn't exist? Or an issue for this enhancement?

@EliiseS
Copy link
Member

EliiseS commented Jul 20, 2020

The change of the default_branch setting failing on update if the branch doesn't exist @jamiemccrindle :)

@ghost ghost added size/M and removed size/XS labels Jul 21, 2020
@jamiemccrindle
Copy link
Author

jamiemccrindle commented Jul 21, 2020

re: raising an issue for the default_branch failing on update if the branch doesn't exist. It's a bit of a tricky one. I think it's reasonable if an update fails if the branch we're setting as the default_branch doesn't exist.

what's arguably more interesting is that the default_branch works when the repo is first created even if the branch doesn't exist. this PR fixes it for the case where the initalization type is 'clean' but it's probably still wrong for uninitialized repos. Only problem is that I think that fixing it for uninitialized repos could be considered a breaking change.

@xuzhang3
Copy link
Collaborator

@jamiemccrindle If you set initialization with init_type: Clean, the default branch masterwill be created. init_type: uninitialized ` won't create the default branch which means no branch exist for the new created repo.

@xuzhang3 xuzhang3 merged commit fd13d78 into microsoft:master Jul 22, 2020
@xuzhang3
Copy link
Collaborator

@jamiemccrindle LGTM, thanks for your contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants