@@ -889,6 +889,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
889
889
} else if (new_upstream ) {
890
890
struct branch * branch = branch_get (argv [0 ]);
891
891
892
+ if (argc > 1 )
893
+ die (_ ("too many branches to set new upstream" ));
894
+
895
+ if (!branch ) {
896
+ if (!argc || !strcmp (argv [0 ], "HEAD" ))
897
+ die (_ ("could not set upstream of HEAD to %s when "
898
+ "it does not point to any branch." ),
899
+ new_upstream );
900
+ die (_ ("no such branch '%s'" ), argv [0 ]);
901
+ }
902
+
892
903
if (!ref_exists (branch -> refname ))
893
904
die (_ ("branch '%s' does not exist" ), branch -> name );
894
905
@@ -901,6 +912,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
901
912
struct branch * branch = branch_get (argv [0 ]);
902
913
struct strbuf buf = STRBUF_INIT ;
903
914
915
+ if (argc > 1 )
916
+ die (_ ("too many branches to unset upstream" ));
917
+
918
+ if (!branch ) {
919
+ if (!argc || !strcmp (argv [0 ], "HEAD" ))
920
+ die (_ ("could not unset upstream of HEAD when "
921
+ "it does not point to any branch." ));
922
+ die (_ ("no such branch '%s'" ), argv [0 ]);
923
+ }
924
+
904
925
if (!branch_has_merge_config (branch )) {
905
926
die (_ ("Branch '%s' has no upstream information" ), branch -> name );
906
927
}
@@ -916,6 +937,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
916
937
int branch_existed = 0 , remote_tracking = 0 ;
917
938
struct strbuf buf = STRBUF_INIT ;
918
939
940
+ if (!strcmp (argv [0 ], "HEAD" ))
941
+ die (_ ("it does not make sense to create 'HEAD' manually" ));
942
+
943
+ if (!branch )
944
+ die (_ ("no such branch '%s'" ), argv [0 ]);
945
+
919
946
if (kinds != REF_LOCAL_BRANCH )
920
947
die (_ ("-a and -r options to 'git branch' do not make sense with a branch name" ));
921
948
0 commit comments