-
Notifications
You must be signed in to change notification settings - Fork 8
Description
We changed the default branch on a repository, and we use the branch name as part of the filenames.
The changing of the default branch caused these two changes:
- +- the file (due to name change)
- +- the default branch
The branch got changed first which means the below code snipped grabbed the commit SHA from branchA which is referenced by the file's branch in state. Then the next step gets the DEFAULT BRANCH (branchB) from the repo's matching commit, and then applies a DELETE of the file only. This however means that the default branch will be reverted to the head commit of the branch referenced in the File's state (our case, branchA). This is then Commited and merged into the default branch, branchB. The PR therefore removes any changes made to branchB since it was last in-sync with branchA.
terraform-provider-githubfile/githubfile/resource_file.go
Lines 131 to 148 in 99b9540
| // Get the tree that corresponds to the target branch. | |
| s, err := branch.GetSHAForBranch(context.Background(), c.githubClient, f.repositoryOwner, f.repositoryName, f.branch) | |
| if err != nil { | |
| return err | |
| } | |
| oldTree, _, err := c.githubClient.Git.GetTree(context.Background(), f.repositoryOwner, f.repositoryName, s, true) | |
| if err != nil { | |
| return err | |
| } | |
| // Remove the target file from the list of entries for the new tree. | |
| // NOTE: Entries of type "tree" must be removed as well, otherwise deletion won't take place. | |
| newTree := make([]github.TreeEntry, 0, len(oldTree.Entries)) | |
| for _, entry := range oldTree.Entries { | |
| if *entry.Type != "tree" && *entry.Path != f.path { | |
| newTree = append(newTree, entry) | |
| } | |
| } |
I'm not sure if we can work out if we should apply the change to the file's branch and then PR that change into the default branch? Possibly change
| oldTree, _, err := c.githubClient.Git.GetTree(context.Background(), f.repositoryOwner, f.repositoryName, s, true) |
This caused the provider to silently remove some extra code from the newly default branch.