Skip to content

Commit

Permalink
pull: check if in unresolved merge state
Browse files Browse the repository at this point in the history
Since d38a30d (Be more user-friendly when refusing to do something
because of conflict., 2010-01-12), git-pull will error out with
user-friendly advices if the user is in the middle of a merge or has
unmerged files.

Re-implement this behavior. While the "has unmerged files" case can be
handled by die_resolve_conflict(), we introduce a new function
die_conclude_merge() for printing a different error message for when
there are no unmerged files but the merge has not been finished.

Signed-off-by: Paul Tan <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pyokagan authored and gitster committed Jun 18, 2015
1 parent a9de989 commit 4a4cf9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions advice.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ void NORETURN die_resolve_conflict(const char *me)
die("Exiting because of an unresolved conflict.");
}

void NORETURN die_conclude_merge(void)
{
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
if (advice_resolve_conflict)
advise(_("Please, commit your changes before you can merge."));
die(_("Exiting because of unfinished merge."));
}

void detach_advice(const char *new_name)
{
const char fmt[] =
Expand Down
1 change: 1 addition & 0 deletions advice.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __attribute__((format (printf, 1, 2)))
void advise(const char *advice, ...);
int error_resolve_conflict(const char *me);
extern void NORETURN die_resolve_conflict(const char *me);
void NORETURN die_conclude_merge(void);
void detach_advice(const char *new_name);

#endif /* ADVICE_H */
9 changes: 9 additions & 0 deletions builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "run-command.h"
#include "sha1-array.h"
#include "remote.h"
#include "dir.h"

static const char * const pull_usage[] = {
N_("git pull [options] [<repository> [<refspec>...]]"),
Expand Down Expand Up @@ -426,6 +427,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (!opt_ff)
opt_ff = xstrdup_or_null(config_get_ff());

git_config(git_default_config, NULL);

if (read_cache_unmerged())
die_resolve_conflict("Pull");

if (file_exists(git_path("MERGE_HEAD")))
die_conclude_merge();

if (run_fetch(repo, refspecs))
return 1;

Expand Down

0 comments on commit 4a4cf9e

Please sign in to comment.