@@ -722,6 +722,7 @@ int cmd_branch(int argc,
722
722
static struct ref_sorting * sorting ;
723
723
struct string_list sorting_options = STRING_LIST_INIT_DUP ;
724
724
struct ref_format format = REF_FORMAT_INIT ;
725
+ int ret ;
725
726
726
727
struct option options [] = {
727
728
OPT_GROUP (N_ ("Generic options" )),
@@ -851,15 +852,15 @@ int cmd_branch(int argc,
851
852
if (list )
852
853
setup_auto_pager ("branch" , 1 );
853
854
854
- UNLEAK (sorting_options );
855
-
856
855
if (delete ) {
857
856
if (!argc )
858
857
die (_ ("branch name required" ));
859
- return delete_branches (argc , argv , delete > 1 , filter .kind , quiet );
858
+ ret = delete_branches (argc , argv , delete > 1 , filter .kind , quiet );
859
+ goto out ;
860
860
} else if (show_current ) {
861
861
print_current_branch_name ();
862
- return 0 ;
862
+ ret = 0 ;
863
+ goto out ;
863
864
} else if (list ) {
864
865
/* git branch --list also shows HEAD when it is detached */
865
866
if ((filter .kind & FILTER_REFS_BRANCHES ) && filter .detached )
@@ -882,12 +883,13 @@ int cmd_branch(int argc,
882
883
ref_sorting_release (sorting );
883
884
ref_filter_clear (& filter );
884
885
ref_format_clear (& format );
885
- return 0 ;
886
+
887
+ ret = 0 ;
888
+ goto out ;
886
889
} else if (edit_description ) {
887
890
const char * branch_name ;
888
891
struct strbuf branch_ref = STRBUF_INIT ;
889
892
struct strbuf buf = STRBUF_INIT ;
890
- int ret = 1 ; /* assume failure */
891
893
892
894
if (!argc ) {
893
895
if (filter .detached )
@@ -901,18 +903,22 @@ int cmd_branch(int argc,
901
903
}
902
904
903
905
strbuf_addf (& branch_ref , "refs/heads/%s" , branch_name );
904
- if (!refs_ref_exists (get_main_ref_store (the_repository ), branch_ref .buf ))
906
+ if (!refs_ref_exists (get_main_ref_store (the_repository ), branch_ref .buf )) {
905
907
error ((!argc || branch_checked_out (branch_ref .buf ))
906
908
? _ ("no commit on branch '%s' yet" )
907
909
: _ ("no branch named '%s'" ),
908
910
branch_name );
909
- else if (!edit_branch_description (branch_name ))
911
+ ret = 1 ;
912
+ } else if (!edit_branch_description (branch_name )) {
910
913
ret = 0 ; /* happy */
914
+ } else {
915
+ ret = 1 ;
916
+ }
911
917
912
918
strbuf_release (& branch_ref );
913
919
strbuf_release (& buf );
914
920
915
- return ret ;
921
+ goto out ;
916
922
} else if (copy || rename ) {
917
923
if (!argc )
918
924
die (_ ("branch name required" ));
@@ -1000,12 +1006,17 @@ int cmd_branch(int argc,
1000
1006
create_branches_recursively (the_repository , branch_name ,
1001
1007
start_name , NULL , force ,
1002
1008
reflog , quiet , track , 0 );
1003
- return 0 ;
1009
+ ret = 0 ;
1010
+ goto out ;
1004
1011
}
1005
1012
create_branch (the_repository , branch_name , start_name , force , 0 ,
1006
1013
reflog , quiet , track , 0 );
1007
1014
} else
1008
1015
usage_with_options (builtin_branch_usage , options );
1009
1016
1010
- return 0 ;
1017
+ ret = 0 ;
1018
+
1019
+ out :
1020
+ string_list_clear (& sorting_options , 0 );
1021
+ return ret ;
1011
1022
}
0 commit comments