@@ -468,10 +468,33 @@ int git_branch_upstream_name(
468468 return error ;
469469}
470470
471- static int git_branch_upstream_with_format (git_buf * buf , git_repository * repo , const char * refname , const char * format )
471+ typedef enum {
472+ GIT_BRANCH_UPSTREAM_FORMAT_REMOTE = 1 ,
473+ GIT_BRANCH_UPSTREAM_FORMAT_MERGE = 2
474+ } git_branch_upstream_format ;
475+
476+ static const char * git_branch_upstream_format_string_for_id (git_branch_upstream_format id ) {
477+ switch (id ) {
478+ case GIT_BRANCH_UPSTREAM_FORMAT_REMOTE : return "branch.%s.remote" ;
479+ case GIT_BRANCH_UPSTREAM_FORMAT_MERGE : return "branch.%s.merge" ;
480+ default : return "" ; // OK?
481+ };
482+ }
483+
484+ static const char * git_branch_upstream_format_name_for_id (git_branch_upstream_format id ) {
485+ switch (id ) {
486+ case GIT_BRANCH_UPSTREAM_FORMAT_REMOTE : return "remote" ;
487+ case GIT_BRANCH_UPSTREAM_FORMAT_MERGE : return "merge" ;
488+ default : return "UNDEFINED" ; // OK?
489+ };
490+ }
491+
492+ static int git_branch_upstream_with_format (git_buf * buf , git_repository * repo , const char * refname , git_branch_upstream_format id )
472493{
473494 int error ;
474495 git_config * cfg ;
496+ const char * format = git_branch_upstream_format_string_for_id (id );
497+ const char * format_name = git_branch_upstream_format_name_for_id (id );
475498
476499 if (!git_reference__is_branch (refname ))
477500 return not_a_local_branch (refname );
@@ -484,7 +507,7 @@ static int git_branch_upstream_with_format(git_buf *buf, git_repository *repo, c
484507 return error ;
485508
486509 if (git_buf_len (buf ) == 0 ) {
487- git_error_set (GIT_ERROR_REFERENCE , "branch '%s' does not have an upstream remote " , refname );
510+ git_error_set (GIT_ERROR_REFERENCE , "branch '%s' does not have an upstream %s " , refname , format_name );
488511 error = GIT_ENOTFOUND ;
489512 git_buf_clear (buf );
490513 }
@@ -494,12 +517,12 @@ static int git_branch_upstream_with_format(git_buf *buf, git_repository *repo, c
494517
495518int git_branch_upstream_remote (git_buf * buf , git_repository * repo , const char * refname )
496519{
497- git_branch_upstream_with_format (buf , repo , refname , "branch.%s.remote" );
520+ return git_branch_upstream_with_format (buf , repo , refname , GIT_BRANCH_UPSTREAM_FORMAT_REMOTE );
498521}
499522
500523int git_branch_upstream_merge (git_buf * buf , git_repository * repo , const char * refname )
501524{
502- git_branch_upstream_with_format (buf , repo , refname , "branch.%s.merge" );
525+ return git_branch_upstream_with_format (buf , repo , refname , GIT_BRANCH_UPSTREAM_FORMAT_MERGE );
503526}
504527
505528int git_branch_remote_name (git_buf * buf , git_repository * repo , const char * refname )
0 commit comments