@@ -939,3 +939,159 @@ func TestFinishReleaseWithMergeContinue(t *testing.T) {
939939 t .Error ("Expected tag 'v1.0.0' to be created" )
940940 }
941941}
942+
943+ // TestFinishNonStandardBranchWithForce tests finishing a non-standard branch with force flag
944+ func TestFinishNonStandardBranchWithForce (t * testing.T ) {
945+ // Setup
946+ dir := testutil .SetupTestRepo (t )
947+ defer testutil .CleanupTestRepo (t , dir )
948+
949+ // Initialize git-flow with defaults
950+ output , err := testutil .RunGitFlow (t , dir , "init" , "-d" , "-c" )
951+ if err != nil {
952+ t .Fatalf ("Failed to initialize git-flow: %v\n Output: %s" , err , output )
953+ }
954+
955+ // Create a non-standard branch from develop
956+ _ , err = testutil .RunGit (t , dir , "checkout" , "develop" )
957+ if err != nil {
958+ t .Fatalf ("Failed to checkout develop: %v" , err )
959+ }
960+ _ , err = testutil .RunGit (t , dir , "checkout" , "-b" , "custom/my-branch" )
961+ if err != nil {
962+ t .Fatalf ("Failed to create custom branch: %v" , err )
963+ }
964+
965+ // Add some changes
966+ testutil .WriteFile (t , dir , "test.txt" , "test content" )
967+ _ , err = testutil .RunGit (t , dir , "add" , "test.txt" )
968+ if err != nil {
969+ t .Fatalf ("Failed to add file: %v" , err )
970+ }
971+ _ , err = testutil .RunGit (t , dir , "commit" , "-m" , "Add test file" )
972+ if err != nil {
973+ t .Fatalf ("Failed to commit file: %v" , err )
974+ }
975+
976+ // Finish the branch using feature strategy with force flag
977+ output , err = testutil .RunGitFlow (t , dir , "feature" , "finish" , "-f" , "custom/my-branch" )
978+ if err != nil {
979+ t .Fatalf ("Failed to finish custom branch: %v\n Output: %s" , err , output )
980+ }
981+
982+ // Verify branch was merged to develop
983+ _ , err = testutil .RunGit (t , dir , "checkout" , "develop" )
984+ if err != nil {
985+ t .Fatalf ("Failed to checkout develop: %v" , err )
986+ }
987+
988+ // Check if test.txt exists in develop
989+ if ! testutil .FileExists (t , dir , "test.txt" ) {
990+ t .Error ("Expected test.txt to exist in develop branch" )
991+ }
992+
993+ // Verify custom branch was deleted
994+ if testutil .BranchExists (t , dir , "custom/my-branch" ) {
995+ t .Error ("Expected custom branch to be deleted" )
996+ }
997+ }
998+
999+ // TestFinishNonStandardBranchWithoutForce tests finishing a non-standard branch without force flag
1000+ func TestFinishNonStandardBranchWithoutForce (t * testing.T ) {
1001+ // Setup
1002+ dir := testutil .SetupTestRepo (t )
1003+ defer testutil .CleanupTestRepo (t , dir )
1004+
1005+ // Initialize git-flow with defaults
1006+ output , err := testutil .RunGitFlow (t , dir , "init" , "-d" , "-c" )
1007+ if err != nil {
1008+ t .Fatalf ("Failed to initialize git-flow: %v\n Output: %s" , err , output )
1009+ }
1010+
1011+ // Create a non-standard branch from develop
1012+ _ , err = testutil .RunGit (t , dir , "checkout" , "develop" )
1013+ if err != nil {
1014+ t .Fatalf ("Failed to checkout develop: %v" , err )
1015+ }
1016+ _ , err = testutil .RunGit (t , dir , "checkout" , "-b" , "custom/my-branch" )
1017+ if err != nil {
1018+ t .Fatalf ("Failed to create custom branch: %v" , err )
1019+ }
1020+
1021+ // Add some changes
1022+ testutil .WriteFile (t , dir , "test.txt" , "test content" )
1023+ _ , err = testutil .RunGit (t , dir , "add" , "test.txt" )
1024+ if err != nil {
1025+ t .Fatalf ("Failed to add file: %v" , err )
1026+ }
1027+ _ , err = testutil .RunGit (t , dir , "commit" , "-m" , "Add test file" )
1028+ if err != nil {
1029+ t .Fatalf ("Failed to commit file: %v" , err )
1030+ }
1031+
1032+ // Try to finish the branch without force flag (should fail)
1033+ output , err = testutil .RunGitFlow (t , dir , "feature" , "finish" , "custom/my-branch" )
1034+ if err == nil {
1035+ t .Fatal ("Expected finish to fail without force flag and user confirmation" )
1036+ }
1037+
1038+ // Verify branch still exists
1039+ if ! testutil .BranchExists (t , dir , "custom/my-branch" ) {
1040+ t .Error ("Expected custom branch to still exist" )
1041+ }
1042+
1043+ // Verify we're still on the custom branch
1044+ currentBranch := testutil .GetCurrentBranch (t , dir )
1045+ if currentBranch != "custom/my-branch" {
1046+ t .Errorf ("Expected to be on custom/my-branch, got %s" , currentBranch )
1047+ }
1048+ }
1049+
1050+ // TestFinishNonStandardBranchWithTag tests finishing a non-standard branch with tag creation
1051+ func TestFinishNonStandardBranchWithTag (t * testing.T ) {
1052+ // Setup
1053+ dir := testutil .SetupTestRepo (t )
1054+ defer testutil .CleanupTestRepo (t , dir )
1055+
1056+ // Initialize git-flow with defaults and tag configuration
1057+ output , err := testutil .RunGitFlow (t , dir , "init" , "-d" , "-c" )
1058+ if err != nil {
1059+ t .Fatalf ("Failed to initialize git-flow: %v\n Output: %s" , err , output )
1060+ }
1061+
1062+ // Create a non-standard branch from develop
1063+ _ , err = testutil .RunGit (t , dir , "checkout" , "develop" )
1064+ if err != nil {
1065+ t .Fatalf ("Failed to checkout develop: %v" , err )
1066+ }
1067+ _ , err = testutil .RunGit (t , dir , "checkout" , "-b" , "custom/my-release" )
1068+ if err != nil {
1069+ t .Fatalf ("Failed to create custom branch: %v" , err )
1070+ }
1071+
1072+ // Add some changes
1073+ testutil .WriteFile (t , dir , "release.txt" , "release content" )
1074+ _ , err = testutil .RunGit (t , dir , "add" , "release.txt" )
1075+ if err != nil {
1076+ t .Fatalf ("Failed to add file: %v" , err )
1077+ }
1078+ _ , err = testutil .RunGit (t , dir , "commit" , "-m" , "Add release file" )
1079+ if err != nil {
1080+ t .Fatalf ("Failed to commit file: %v" , err )
1081+ }
1082+
1083+ // Finish the branch using release strategy with force flag
1084+ output , err = testutil .RunGitFlow (t , dir , "release" , "finish" , "-f" , "custom/my-release" )
1085+ if err != nil {
1086+ t .Fatalf ("Failed to finish custom release branch: %v\n Output: %s" , err , output )
1087+ }
1088+
1089+ // Verify tag was created
1090+ tagExists , err := testutil .RunGit (t , dir , "tag" , "-l" , "my-release" )
1091+ if err != nil {
1092+ t .Fatalf ("Failed to list tags: %v" , err )
1093+ }
1094+ if tagExists == "" {
1095+ t .Error ("Expected tag 'my-release' to exist" )
1096+ }
1097+ }
0 commit comments