25
25
#include "help.h"
26
26
#include "merge-recursive.h"
27
27
#include "resolve-undo.h"
28
+ #include "remote.h"
28
29
29
30
#define DEFAULT_TWOHEAD (1<<0)
30
31
#define DEFAULT_OCTOPUS (1<<1)
@@ -37,8 +38,9 @@ struct strategy {
37
38
};
38
39
39
40
static const char * const builtin_merge_usage [] = {
40
- "git merge [options] <remote>..." ,
41
- "git merge [options] <msg> HEAD <remote>" ,
41
+ "git merge [options] [<commit>...]" ,
42
+ "git merge [options] <msg> HEAD <commit>" ,
43
+ "git merge --abort" ,
42
44
NULL
43
45
};
44
46
@@ -59,6 +61,7 @@ static int verbosity;
59
61
static int allow_rerere_auto ;
60
62
static int abort_current_merge ;
61
63
static int show_progress = -1 ;
64
+ static int default_to_upstream ;
62
65
63
66
static struct strategy all_strategy [] = {
64
67
{ "recursive" , DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -538,6 +541,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)
538
541
if (is_bool && shortlog_len )
539
542
shortlog_len = DEFAULT_MERGE_LOG_LEN ;
540
543
return 0 ;
544
+ } else if (!strcmp (k , "merge.defaulttoupstream" )) {
545
+ default_to_upstream = git_config_bool (k , v );
546
+ return 0 ;
541
547
}
542
548
return git_diff_ui_config (k , v , cb );
543
549
}
@@ -945,6 +951,35 @@ static int evaluate_result(void)
945
951
return cnt ;
946
952
}
947
953
954
+ /*
955
+ * Pretend as if the user told us to merge with the tracking
956
+ * branch we have for the upstream of the current branch
957
+ */
958
+ static int setup_with_upstream (const char * * * argv )
959
+ {
960
+ struct branch * branch = branch_get (NULL );
961
+ int i ;
962
+ const char * * args ;
963
+
964
+ if (!branch )
965
+ die ("No current branch." );
966
+ if (!branch -> remote )
967
+ die ("No remote for the current branch." );
968
+ if (!branch -> merge_nr )
969
+ die ("No default upstream defined for the current branch." );
970
+
971
+ args = xcalloc (branch -> merge_nr + 1 , sizeof (char * ));
972
+ for (i = 0 ; i < branch -> merge_nr ; i ++ ) {
973
+ if (!branch -> merge [i ]-> dst )
974
+ die ("No remote tracking branch for %s from %s" ,
975
+ branch -> merge [i ]-> src , branch -> remote_name );
976
+ args [i ] = branch -> merge [i ]-> dst ;
977
+ }
978
+ args [i ] = NULL ;
979
+ * argv = args ;
980
+ return i ;
981
+ }
982
+
948
983
int cmd_merge (int argc , const char * * argv , const char * prefix )
949
984
{
950
985
unsigned char result_tree [20 ];
@@ -1027,6 +1062,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1027
1062
if (!allow_fast_forward && fast_forward_only )
1028
1063
die (_ ("You cannot combine --no-ff with --ff-only." ));
1029
1064
1065
+ if (!argc && !abort_current_merge && default_to_upstream )
1066
+ argc = setup_with_upstream (& argv );
1067
+
1030
1068
if (!argc )
1031
1069
usage_with_options (builtin_merge_usage ,
1032
1070
builtin_merge_options );
0 commit comments