@@ -520,13 +520,6 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
520
520
const char * interpreted_newname = NULL ;
521
521
int recovery = 0 ;
522
522
523
- if (!oldname ) {
524
- if (copy )
525
- die (_ ("cannot copy the current branch while not on any." ));
526
- else
527
- die (_ ("cannot rename the current branch while not on any." ));
528
- }
529
-
530
523
if (strbuf_check_branch_ref (& oldref , oldname )) {
531
524
/*
532
525
* Bad name --- this could be an attempt to rename a
@@ -827,24 +820,19 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
827
820
strbuf_release (& buf );
828
821
829
822
return ret ;
830
- } else if (copy ) {
831
- if (!argc )
832
- die (_ ("branch name required" ));
833
- else if (argc == 1 )
834
- copy_or_rename_branch (head , argv [0 ], 1 , copy > 1 );
835
- else if (argc == 2 )
836
- copy_or_rename_branch (argv [0 ], argv [1 ], 1 , copy > 1 );
837
- else
838
- die (_ ("too many branches for a copy operation" ));
839
- } else if (rename ) {
823
+ } else if (copy || rename ) {
840
824
if (!argc )
841
825
die (_ ("branch name required" ));
826
+ else if ((argc == 1 ) && filter .detached )
827
+ die (copy ? _ ("cannot copy the current branch while not on any." )
828
+ : _ ("cannot rename the current branch while not on any." ));
842
829
else if (argc == 1 )
843
- copy_or_rename_branch (head , argv [0 ], 0 , rename > 1 );
830
+ copy_or_rename_branch (head , argv [0 ], copy , copy + rename > 1 );
844
831
else if (argc == 2 )
845
- copy_or_rename_branch (argv [0 ], argv [1 ], 0 , rename > 1 );
832
+ copy_or_rename_branch (argv [0 ], argv [1 ], copy , copy + rename > 1 );
846
833
else
847
- die (_ ("too many arguments for a rename operation" ));
834
+ die (copy ? _ ("too many branches for a copy operation" )
835
+ : _ ("too many arguments for a rename operation" ));
848
836
} else if (new_upstream ) {
849
837
struct branch * branch ;
850
838
struct strbuf buf = STRBUF_INIT ;
0 commit comments