@@ -15,6 +15,7 @@ func resourceGithubBranch() *schema.Resource {
1515 return & schema.Resource {
1616 Create : resourceGithubBranchCreate ,
1717 Read : resourceGithubBranchRead ,
18+ Update : resourceGithubBranchUpdate ,
1819 Delete : resourceGithubBranchDelete ,
1920 Importer : & schema.ResourceImporter {
2021 State : resourceGithubBranchImport ,
@@ -30,7 +31,6 @@ func resourceGithubBranch() *schema.Resource {
3031 "branch" : {
3132 Type : schema .TypeString ,
3233 Required : true ,
33- ForceNew : true ,
3434 Description : "The repository branch to create." ,
3535 },
3636 "source_branch" : {
@@ -184,6 +184,29 @@ func resourceGithubBranchDelete(d *schema.ResourceData, meta interface{}) error
184184 return nil
185185}
186186
187+ func resourceGithubBranchUpdate (d * schema.ResourceData , meta interface {}) error {
188+ if ! d .HasChange ("branch" ) {
189+ return resourceGithubBranchRead (d , meta )
190+ }
191+
192+ ctx := context .WithValue (context .Background (), ctxId , d .Id ())
193+ client := meta .(* Owner ).v3client
194+ orgName := meta .(* Owner ).name
195+ repoName , oldBranchName , err := parseTwoPartID (d .Id (), "repository" , "branch" )
196+ if err != nil {
197+ return err
198+ }
199+ newBranchName := d .Get ("branch" ).(string )
200+
201+ if _ , _ , err := client .Repositories .RenameBranch (ctx , orgName , repoName , oldBranchName , newBranchName ); err != nil {
202+ return fmt .Errorf ("error renaming GitHub branch %s/%s (%s -> %s): %w" , orgName , repoName , oldBranchName , newBranchName , err )
203+ }
204+
205+ d .SetId (buildTwoPartID (repoName , newBranchName ))
206+
207+ return resourceGithubBranchRead (d , meta )
208+ }
209+
187210func resourceGithubBranchImport (d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
188211 repoName , branchName , err := parseTwoPartID (d .Id (), "repository" , "branch" )
189212 if err != nil {
0 commit comments