Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@ func performDelete(branchType, name, fullBranchName string, branchConfig config.
remoteName = "origin"
}

// Delete remote branch
if err := git.DeleteRemoteBranch(remoteName, fullBranchName); err != nil {
return &errors.GitError{Operation: fmt.Sprintf("delete remote branch '%s'", fullBranchName), Err: err}
deletedRemote := false
if git.RemoteBranchExists(remoteName, fullBranchName) {
// Delete remote branch
if err := git.DeleteRemoteBranch(remoteName, fullBranchName); err != nil {
return &errors.GitError{Operation: fmt.Sprintf("delete remote branch '%s'", fullBranchName), Err: err}
} else {
deletedRemote = true
}
}
if deletedRemote {
fmt.Printf("Deleted branch %s and its remote tracking branch\n", fullBranchName)
} else {
fmt.Printf("Deleted branch %s (no remote tracking branch found)\n", fullBranchName)
}
fmt.Printf("Deleted branch %s and its remote tracking branch\n", fullBranchName)
} else {
fmt.Printf("Deleted branch %s\n", fullBranchName)
}
Expand Down
8 changes: 4 additions & 4 deletions test/cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func TestDeleteFeatureWithCommandLineOverride(t *testing.T) {
// 3. Adds a remote repository but doesn't push the branch
// 4. Attempts to delete the branch with --remote flag
// 5. Verifies the branch is deleted locally
// 6. Verifies an error occurs when trying to delete the non-existent remote branch
// 6. Verifies no error occurs when trying to delete the non-existent remote branch
func TestDeleteFeatureWithNonExistentRemote(t *testing.T) {
// Setup test repository
dir := testutil.SetupTestRepo(t)
Expand Down Expand Up @@ -476,10 +476,10 @@ func TestDeleteFeatureWithNonExistentRemote(t *testing.T) {
t.Fatalf("Feature branch unexpectedly exists on remote")
}

// Delete feature branch with remote deletion - should fail
// Delete feature branch with remote deletion - should succeed
_, err = testutil.RunGitFlow(t, dir, "feature", "delete", "test-feature", "--remote")
if err == nil {
t.Fatalf("Expected error when deleting non-existent remote branch")
if err != nil {
t.Fatalf("Failed to delete remote: %v", err)
}

// Verify branch is deleted locally
Expand Down