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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Nov 22, 2009 at 23:26 UTC
4c371f91270792791f867d15f25b03f800ab35a1
4 files changed
+14
-1
Documentation/config.txt
+4
@@ -126,6 +126,10 @@ advice.*::
126
Directions on how to stage/unstage/add shown in the
127
output of linkgit:git-status[1] and the template shown
128
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.
133
--
134
135
core.fileMode::
advice.c
+2
@@ -2,6 +2,7 @@
2
3
int advice_push_nonfastforward = 1;
4
int advice_status_hints = 1;
5
+int advice_commit_before_merge = 1;
6
7
static struct {
8
const char *name;
@@ -9,6 +10,7 @@ static struct {
10
} advice_config[] = {
11
{ "pushnonfastforward", &advice_push_nonfastforward },
12
{ "statushints", &advice_status_hints },
13
+ { "commitbeforemerge", &advice_commit_before_merge },
14
};
15
16
int git_default_advice_config(const char *var, const char *value)
advice.h
+1
@@ -3,6 +3,7 @@
3
4
extern int advice_push_nonfastforward;
5
extern int advice_status_hints;
6
+extern int advice_commit_before_merge;
7
8
int git_default_advice_config(const char *var, const char *value);
9
merge-recursive.c
+7
-1
@@ -3,6 +3,7 @@
3
* Fredrik Kuivinen.
4
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
5
*/
6
+#include "advice.h"
7
#include "cache.h"
8
#include "cache-tree.h"
9
#include "commit.h"
@@ -170,7 +171,7 @@ static int git_merge_trees(int index_only,
171
int rc;
172
struct tree_desc t[3];
173
struct unpack_trees_options opts;
173
- static const struct unpack_trees_error_msgs msgs = {
174
+ struct unpack_trees_error_msgs msgs = {
175
/* would_overwrite */
176
"Your local changes to '%s' would be overwritten by merge. Aborting.",
177
/* not_uptodate_file */
@@ -182,6 +183,11 @@ static int git_merge_trees(int index_only,
183
/* bind_overlap -- will not happen here */
184
NULL,
185
};
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
+ }
191
192
memset(&opts, 0, sizeof(opts));
193
if (index_only)