The display of the advice '(use git add/rm [...])' (when there are unmerged files) after running 'git status' is now depending of the mark, whether it's 'both deleted', 'deleted by us/them' or others. For instance, when there is just one file that's marked as 'both deleted', 'git status' shows '(use git rm [...])' and if there are two files, one as 'both deleted' and the other as 'added by them', the advice is '(use git add/rm [...])'. The previous tests in t7512-status-warnings.sh are updated and 5 tests are added about the different cases of unmerged paths. Signed-off-by: Kong Lucien <Lucien.Kong@xxxxxxxxxxxxxxx> Signed-off-by: Duperray Valentin <Valentin.Duperray@xxxxxxxxxxxxxxx> Signed-off-by: Jonas Franck <Franck.Jonas@xxxxxxxxxxxxxxx> Signed-off-by: Nguy Thomas <Thomas.Nguy@xxxxxxxxxxxxxxx> Signed-off-by: Nguyen Huynh Khoi Nguyen Lucien <Huynh-Khoi-Nguyen.Nguyen@xxxxxxxxxxxxxxx> --- t/t7512-status-warnings.sh | 165 ++++++++++++++++++++++++++++++++++++++++++- wt-status.c | 29 ++++++++- 2 files changed, 189 insertions(+), 5 deletions(-) diff --git a/t/t7512-status-warnings.sh b/t/t7512-status-warnings.sh index 2806fe8..01d614c 100755 --- a/t/t7512-status-warnings.sh +++ b/t/t7512-status-warnings.sh @@ -27,7 +27,7 @@ test_expect_success 'status when conflicts unresolved' ' # You have unmerged paths; fix conflicts and run "git commit". # # Unmerged paths: - # (use "git add/rm <file>..." as appropriate to mark resolution) + # (use "git add <file>..." as appropriate to mark resolution) # # both modified: main.txt # @@ -78,7 +78,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts' # # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) - # (use "git add/rm <file>..." as appropriate to mark resolution) + # (use "git add <file>..." as appropriate to mark resolution) # # both modified: main.txt # @@ -280,7 +280,7 @@ test_expect_success 'status when rebase conflicts with statushelp disabled' ' # # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) - # (use "git add/rm <file>..." as appropriate to mark resolution) + # (use "git add <file>..." as appropriate to mark resolution) # # both modified: main.txt # @@ -311,7 +311,7 @@ test_expect_success 'status when cherry-picking before resolving conflicts' ' # You are currently cherry-picking: fix conflicts and run "git commit". # # Unmerged paths: - # (use "git add/rm <file>..." as appropriate to mark resolution) + # (use "git add <file>..." as appropriate to mark resolution) # # both modified: main.txt # @@ -349,4 +349,161 @@ test_expect_success 'status when cherry-picking after resolving conflicts' ' ' +test_expect_success 'status when conflicts without rm advice (both modified)' ' + git init git && + cd git && + test_when_finished "cd ../ && rm -rf git" && + test_commit init main.txt init && + git branch second_branch && + test_commit on_master main.txt on_master && + git checkout second_branch && + test_commit on_second_branch main.txt on_second_branch && + test_must_fail git merge master && + cat >expect <<-\EOF && + # On branch second_branch + # You have unmerged paths; fix conflicts and run "git commit". + # + # Unmerged paths: + # (use "git add <file>..." as appropriate to mark resolution) + # + # both modified: main.txt + # + # Untracked files: + # (use "git add <file>..." to include in what will be committed) + # + # expect + # output + no changes added to commit (use "git add" and/or "git commit -a") + EOF + git status >output && + test_cmp expect output +' + + +test_expect_success 'status when conflicts with add and rm advice (deleted by us)' ' + git init git && + cd git && + test_when_finished "cd ../ && rm -rf git" && + test_commit init main.txt init && + git branch second_branch && + test_commit on_master main.txt on_master && + git checkout second_branch && + git rm main.txt && + git commit -m "main.txt deleted on second_branch" && + test_must_fail git merge master && + cat >expect <<-\EOF && + # On branch second_branch + # You have unmerged paths; fix conflicts and run "git commit". + # + # Unmerged paths: + # (use "git add/rm <file>..." as appropriate to mark resolution) + # + # deleted by us: main.txt + # + # Untracked files: + # (use "git add <file>..." to include in what will be committed) + # + # expect + # output + no changes added to commit (use "git add" and/or "git commit -a") + EOF + git status >output && + test_cmp expect output +' + + +test_expect_success 'status when conflicts with add and rm advice (deleted by them)' ' + git init git && + cd git && + test_when_finished "cd ../ && rm -rf git" && + test_commit init main.txt init && + git branch second_branch && + git rm main.txt && + git commit -m "main.txt deleted on master" && + git checkout second_branch && + test_commit on_second main.txt on_second && + test_must_fail git merge master && + cat >expect <<-\EOF && + # On branch second_branch + # You have unmerged paths; fix conflicts and run "git commit". + # + # Unmerged paths: + # (use "git add/rm <file>..." as appropriate to mark resolution) + # + # deleted by them: main.txt + # + # Untracked files: + # (use "git add <file>..." to include in what will be committed) + # + # expect + # output + no changes added to commit (use "git add" and/or "git commit -a") + EOF + git status >output && + test_cmp expect output +' + + +test_expect_success 'status when conflicts with add and rm advice (both deleted)' ' + git init git && + cd git && + test_commit init main.txt init && + git branch second_branch && + git mv main.txt sub_master.txt && + git commit -m "main.txt renamed in sub_master.txt" && + git checkout second_branch && + git mv main.txt sub_second.txt && + git commit -m "main.txt renamed in sub_second.txt" && + test_must_fail git merge master && + cat >expect <<-\EOF && + # On branch second_branch + # You have unmerged paths; fix conflicts and run "git commit". + # + # Unmerged paths: + # (use "git add/rm <file>..." as appropriate to mark resolution) + # + # both deleted: main.txt + # added by them: sub_master.txt + # added by us: sub_second.txt + # + # Untracked files: + # (use "git add <file>..." to include in what will be committed) + # + # expect + # output + no changes added to commit (use "git add" and/or "git commit -a") + EOF + git status >output && + test_cmp expect output +' + + +test_expect_success 'status when conflicts with only rm advice (both deleted)' ' + test_when_finished "cd ../ && rm -rf git" && + git add sub_master.txt && + git add sub_second.txt && + cat >expect <<-\EOF && + # On branch second_branch + # You have unmerged paths; fix conflicts and run "git commit". + # + # Changes to be committed: + # + # new file: sub_master.txt + # + # Unmerged paths: + # (use "git rm <file>..." as appropriate to mark resolution) + # + # both deleted: main.txt + # + # Untracked files: + # (use "git add <file>..." to include in what will be committed) + # + # expect + # output + EOF + git status >output && + test_cmp expect output +' + + test_done diff --git a/wt-status.c b/wt-status.c index 4dd294f..9d79f2b 100644 --- a/wt-status.c +++ b/wt-status.c @@ -131,9 +131,27 @@ void wt_status_prepare(struct wt_status *s) static void wt_status_print_unmerged_header(struct wt_status *s) { + int i; + int simple_deleted_flag = 0; + int both_deleted_flag = 0; + int not_deleted_flag = 0; const char *c = color(WT_STATUS_HEADER, s); status_printf_ln(s, c, _("Unmerged paths:")); + + for (i = 0; i < s->change.nr; i++) { + struct string_list_item *it = &(s->change.items[i]); + struct wt_status_change_data *d = it->util; + + if (d->stagemask == 1 && !both_deleted_flag) + both_deleted_flag = 1; + else if ((d->stagemask == 3 || d->stagemask == 5) && !simple_deleted_flag) + simple_deleted_flag = 1; + else if ((d->stagemask == 2 || d->stagemask == 4 || d->stagemask == 6 || + d->stagemask == 7) && !not_deleted_flag) + not_deleted_flag = 1; + } + if (!advice_status_hints) return; if (s->whence != FROM_COMMIT) @@ -142,7 +160,16 @@ static void wt_status_print_unmerged_header(struct wt_status *s) status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference); else status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)")); - status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)")); + + if (!both_deleted_flag) + if (!simple_deleted_flag) + status_printf_ln(s, c, _(" (use \"git add <file>...\" as appropriate to mark resolution)")); + else + status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)")); + else if (!simple_deleted_flag && !not_deleted_flag) + status_printf_ln(s, c, _(" (use \"git rm <file>...\" as appropriate to mark resolution)")); + else + status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)")); status_printf_ln(s, c, ""); } -- 1.7.8 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html