Skip to content

Commit 4c371f9

Browse files
moygitster
authored andcommitted
merge-recursive: point the user to commit when file would be overwritten.
The commit-before-pull is well accepted in the DVCS community, but is confusing some new users. This should get them back in the right way when the problem occurs. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78d553b commit 4c371f9

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ advice.*::
126126
Directions on how to stage/unstage/add shown in the
127127
output of linkgit:git-status[1] and the template shown
128128
when writing commit messages. Default: true.
129+
commitBeforeMerge::
130+
Advice shown when linkgit:git-merge[1] refuses to
131+
merge to avoid overwritting local changes.
132+
Default: true.
129133
--
130134

131135
core.fileMode::

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
int advice_push_nonfastforward = 1;
44
int advice_status_hints = 1;
5+
int advice_commit_before_merge = 1;
56

67
static struct {
78
const char *name;
89
int *preference;
910
} advice_config[] = {
1011
{ "pushnonfastforward", &advice_push_nonfastforward },
1112
{ "statushints", &advice_status_hints },
13+
{ "commitbeforemerge", &advice_commit_before_merge },
1214
};
1315

1416
int git_default_advice_config(const char *var, const char *value)

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
extern int advice_push_nonfastforward;
55
extern int advice_status_hints;
6+
extern int advice_commit_before_merge;
67

78
int git_default_advice_config(const char *var, const char *value);
89

merge-recursive.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Fredrik Kuivinen.
44
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
55
*/
6+
#include "advice.h"
67
#include "cache.h"
78
#include "cache-tree.h"
89
#include "commit.h"
@@ -170,7 +171,7 @@ static int git_merge_trees(int index_only,
170171
int rc;
171172
struct tree_desc t[3];
172173
struct unpack_trees_options opts;
173-
static const struct unpack_trees_error_msgs msgs = {
174+
struct unpack_trees_error_msgs msgs = {
174175
/* would_overwrite */
175176
"Your local changes to '%s' would be overwritten by merge. Aborting.",
176177
/* not_uptodate_file */
@@ -182,6 +183,11 @@ static int git_merge_trees(int index_only,
182183
/* bind_overlap -- will not happen here */
183184
NULL,
184185
};
186+
if (advice_commit_before_merge) {
187+
msgs.would_overwrite = msgs.not_uptodate_file =
188+
"Your local changes to '%s' would be overwritten by merge. Aborting.\n"
189+
"Please, commit your changes or stash them before you can merge.";
190+
}
185191

186192
memset(&opts, 0, sizeof(opts));
187193
if (index_only)

0 commit comments

Comments
 (0)