Skip to content

Commit

Permalink
status/commit: do not suggest "reset HEAD <path>" while merging
Browse files Browse the repository at this point in the history
Suggesting "'reset HEAD <path>' to unstage" is dead wrong if we are about
to record a merge commit.  For either an unmerged path (i.e. with
unresolved conflicts), or an updated path, it would result in discarding
what the other branch did.

Note that we do not do anything special in a case where we are amending a
merge.  The user is making an evil merge starting from an already
committed merge, and running "reset HEAD <path>" is the right way to get
rid of the local edit that has been added to the index.

Once "reset --unresolve <path>" becomes available, we might want to
suggest it for a merged path that has unresolve information, but until
then, just remove the incorrect advice.

We might also want to suggest "checkout --conflict <path>" to revert the
file in the work tree to the state of failed automerge for an unmerged
path, but we never did that, and this commit does not change that.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Dec 12, 2009
1 parent dd20f8a commit 3c58845
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
read_cache();
refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
s.in_merge = in_merge;
wt_status_collect(&s);

if (s.relative_paths)
Expand Down Expand Up @@ -1056,6 +1057,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
wt_status_prepare(&s);
git_config(git_commit_config, &s);
in_merge = file_exists(git_path("MERGE_HEAD"));
s.in_merge = in_merge;

if (s.use_color == -1)
s.use_color = git_use_color_default;
Expand Down
1 change: 0 additions & 1 deletion t/t7060-wtstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test_expect_success 'Report new path with conflict' '
cat >expect <<EOF
# On branch side
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# deleted by us: foo
Expand Down
14 changes: 10 additions & 4 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ void wt_status_prepare(struct wt_status *s)
static void wt_status_print_unmerged_header(struct wt_status *s)
{
const char *c = color(WT_STATUS_HEADER, s);

color_fprintf_ln(s->fp, c, "# Unmerged paths:");
if (!s->is_initial)
if (s->in_merge)
;
else if (!s->is_initial)
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
else
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
Expand All @@ -59,19 +62,22 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
static void wt_status_print_cached_header(struct wt_status *s)
{
const char *c = color(WT_STATUS_HEADER, s);

color_fprintf_ln(s->fp, c, "# Changes to be committed:");
if (!s->is_initial) {
if (s->in_merge)
; /* NEEDSWORK: use "git reset --unresolve"??? */
else if (!s->is_initial)
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
} else {
else
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
}
color_fprintf_ln(s->fp, c, "#");
}

static void wt_status_print_dirty_header(struct wt_status *s,
int has_deleted)
{
const char *c = color(WT_STATUS_HEADER, s);

color_fprintf_ln(s->fp, c, "# Changed but not updated:");
if (!has_deleted)
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
Expand Down
1 change: 1 addition & 0 deletions wt-status.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct wt_status {
const char **pathspec;
int verbose;
int amend;
int in_merge;
int nowarn;
int use_color;
int relative_paths;
Expand Down

0 comments on commit 3c58845

Please sign in to comment.