Skip to content

Commit

Permalink
merge-recursive: point the user to commit when file would be overwrit…
Browse files Browse the repository at this point in the history
…ten.

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>
  • Loading branch information
Matthieu Moy authored and Junio C Hamano committed Nov 23, 2009
1 parent 78d553b commit 4c371f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ advice.*::
Directions on how to stage/unstage/add shown in the
output of linkgit:git-status[1] and the template shown
when writing commit messages. Default: true.
commitBeforeMerge::
Advice shown when linkgit:git-merge[1] refuses to
merge to avoid overwritting local changes.
Default: true.
--

core.fileMode::
Expand Down
2 changes: 2 additions & 0 deletions advice.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

int advice_push_nonfastforward = 1;
int advice_status_hints = 1;
int advice_commit_before_merge = 1;

static struct {
const char *name;
int *preference;
} advice_config[] = {
{ "pushnonfastforward", &advice_push_nonfastforward },
{ "statushints", &advice_status_hints },
{ "commitbeforemerge", &advice_commit_before_merge },
};

int git_default_advice_config(const char *var, const char *value)
Expand Down
1 change: 1 addition & 0 deletions advice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

extern int advice_push_nonfastforward;
extern int advice_status_hints;
extern int advice_commit_before_merge;

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

Expand Down
8 changes: 7 additions & 1 deletion merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
#include "advice.h"
#include "cache.h"
#include "cache-tree.h"
#include "commit.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ static int git_merge_trees(int index_only,
int rc;
struct tree_desc t[3];
struct unpack_trees_options opts;
static const struct unpack_trees_error_msgs msgs = {
struct unpack_trees_error_msgs msgs = {
/* would_overwrite */
"Your local changes to '%s' would be overwritten by merge. Aborting.",
/* not_uptodate_file */
Expand All @@ -182,6 +183,11 @@ static int git_merge_trees(int index_only,
/* bind_overlap -- will not happen here */
NULL,
};
if (advice_commit_before_merge) {
msgs.would_overwrite = msgs.not_uptodate_file =
"Your local changes to '%s' would be overwritten by merge. Aborting.\n"
"Please, commit your changes or stash them before you can merge.";
}

memset(&opts, 0, sizeof(opts));
if (index_only)
Expand Down

0 comments on commit 4c371f9

Please sign in to comment.