{"thread":{"id":"15414","subject":"[RFC PATCH 0/2] Teach how to discard changes in the working directory","startedAt":"2008-09-07T22:05:01Z","lastAt":"2008-09-07T23:32:16Z","messageCount":6,"participants":["Anders Melchiorsen","Junio C Hamano","Pieter de Bie"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"90012","messageId":"1220825103-19599-1-git-send-email-mail@cup.kalibalik.dk","threadId":"15414","inReplyTo":null,"subject":"[RFC PATCH 0/2] Teach how to discard changes in the working directory","fromName":"Anders Melchiorsen","fromEmail":"mail@cup.kalibalik.dk","sentAt":"2008-09-07T22:05:01Z","receivedAt":"2008-09-07T22:05:01Z","isPatch":true,"sender":{"key":"mail@cup.kalibalik.dk","avatar":null},"body":"\nUsing \"git checkout\" to undo local changes is a hint that is often\ngiven in #git. This patch (part 2) adds the hint into the status\noutput. A bit of restructuring appears in the initial patch.\n\nThis is merely an RFC, I am not sure whether I like it myself :-).\n\n\nAnders.\n"},{"id":"90014","messageId":"1220825103-19599-2-git-send-email-mail@cup.kalibalik.dk","threadId":"15414","inReplyTo":"1220825103-19599-1-git-send-email-mail@cup.kalibalik.dk","subject":"[RFC PATCH 1/2] wt-status: Split header generation into three functions","fromName":"Anders Melchiorsen","fromEmail":"mail@cup.kalibalik.dk","sentAt":"2008-09-07T22:05:02Z","receivedAt":"2008-09-07T22:05:02Z","isPatch":true,"sender":{"key":"mail@cup.kalibalik.dk","avatar":null},"body":"Reorganize header generation so that all header text related to each\nblock is in one place.\n\nThis adds a function, but makes it easier to see what is generated in\neach case. It also allows for easy tweaking of individual headers.\n---\n wt-status.c |   35 ++++++++++++++++++++---------------\n 1 files changed, 20 insertions(+), 15 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 889e50f..ceb3a1e 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -22,12 +22,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = {\n \t\"\\033[31m\", /* WT_STATUS_NOBRANCH: red */\n };\n \n-static const char use_add_msg[] =\n-\"use \\\"git add <file>...\\\" to update what will be committed\";\n-static const char use_add_rm_msg[] =\n-\"use \\\"git add/rm <file>...\\\" to update what will be committed\";\n-static const char use_add_to_include_msg[] =\n-\"use \\\"git add <file>...\\\" to include in what will be committed\";\n enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n \n static int parse_status_slot(const char *var, int offset)\n@@ -76,12 +70,24 @@ static void wt_status_print_cached_header(struct wt_status *s)\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n-static void wt_status_print_header(struct wt_status *s,\n-\t\t\t\t   const char *main, const char *sub)\n+static void wt_status_print_dirty_header(struct wt_status *s,\n+\t\t\t\t\t int has_deleted)\n {\n \tconst char *c = color(WT_STATUS_HEADER);\n-\tcolor_fprintf_ln(s->fp, c, \"# %s:\", main);\n-\tcolor_fprintf_ln(s->fp, c, \"#   (%s)\", sub);\n+\tcolor_fprintf_ln(s->fp, c, \"# Changed but not updated:\");\n+\tif (!has_deleted) {\n+\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add <file>...\\\" to update what will be committed)\");\n+\t} else {\n+\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" to update what will be committed)\");\n+\t}\n+\tcolor_fprintf_ln(s->fp, c, \"#\");\n+}\n+\n+static void wt_status_print_untracked_header(struct wt_status *s)\n+{\n+\tconst char *c = color(WT_STATUS_HEADER);\n+\tcolor_fprintf_ln(s->fp, c, \"# Untracked files:\");\n+\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add <file>...\\\" to include in what will be committed)\");\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n@@ -166,14 +172,14 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,\n \tstruct wt_status *s = data;\n \tint i;\n \tif (q->nr) {\n-\t\tconst char *msg = use_add_msg;\n+\t\tint has_deleted = 0;\n \t\ts->workdir_dirty = 1;\n \t\tfor (i = 0; i < q->nr; i++)\n \t\t\tif (q->queue[i]->status == DIFF_STATUS_DELETED) {\n-\t\t\t\tmsg = use_add_rm_msg;\n+\t\t\t\thas_deleted = 1;\n \t\t\t\tbreak;\n \t\t\t}\n-\t\twt_status_print_header(s, \"Changed but not updated\", msg);\n+\t\twt_status_print_dirty_header(s, has_deleted);\n \t}\n \tfor (i = 0; i < q->nr; i++)\n \t\twt_status_print_filepair(s, WT_STATUS_CHANGED, q->queue[i]);\n@@ -291,8 +297,7 @@ static void wt_status_print_untracked(struct wt_status *s)\n \t\t}\n \t\tif (!shown_header) {\n \t\t\ts->workdir_untracked = 1;\n-\t\t\twt_status_print_header(s, \"Untracked files\",\n-\t\t\t\t\t       use_add_to_include_msg);\n+\t\t\twt_status_print_untracked_header(s);\n \t\t\tshown_header = 1;\n \t\t}\n \t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER), \"#\\t\");\n-- \n1.6.0.1.dirty\n"},{"id":"90013","messageId":"1220825103-19599-3-git-send-email-mail@cup.kalibalik.dk","threadId":"15414","inReplyTo":"1220825103-19599-2-git-send-email-mail@cup.kalibalik.dk","subject":"[RFC PATCH 2/2] wt-status: Teach how to discard changes in the working directory","fromName":"Anders Melchiorsen","fromEmail":"mail@cup.kalibalik.dk","sentAt":"2008-09-07T22:05:03Z","receivedAt":"2008-09-07T22:05:03Z","isPatch":true,"sender":{"key":"mail@cup.kalibalik.dk","avatar":null},"body":"This is a question that comes up a lot in #git.\n---\n t/t7502-status.sh |   10 ++++++++++\n wt-status.c       |    1 +\n 2 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex ceb3a1e..5bc3e36 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -80,6 +80,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,\n \t} else {\n \t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" to update what will be committed)\");\n \t}\n+\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git checkout -- <file>...\\\" to discard changes in working directory)\");\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \ndiff --git a/t/t7502-status.sh b/t/t7502-status.sh\nindex 38a48b5..efa1239 100755\n--- a/t/t7502-status.sh\n+++ b/t/t7502-status.sh\n@@ -46,6 +46,7 @@ cat > expect << \\EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -76,6 +77,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -104,6 +106,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -138,6 +141,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -174,6 +178,7 @@ cat > expect << \\EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   modified\n #\n@@ -204,6 +209,7 @@ cat > expect << \\EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -267,6 +273,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -297,6 +304,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -326,6 +334,7 @@ cat >expect <<EOF\n # On branch master\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n@@ -357,7 +366,7 @@ cat >expect <<EOF\n #\n # Changed but not updated:\n #   (use \"git add <file>...\" to update what will be committed)\n+#   (use \"git checkout -- <file>...\" to discard changes in working directory)\n #\n #\tmodified:   dir1/modified\n #\n-- \n1.6.0.1.dirty\n"},{"id":"90017","messageId":"7vtzcrk1wt.fsf@gitster.siamese.dyndns.org","threadId":"15414","inReplyTo":"1220825103-19599-1-git-send-email-mail@cup.kalibalik.dk","subject":"Re: [RFC PATCH 0/2] Teach how to discard changes in the working directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-07T22:48:50Z","receivedAt":"2008-09-07T22:48:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Anders Melchiorsen <mail@cup.kalibalik.dk> writes:\n\n> Using \"git checkout\" to undo local changes is a hint that is often\n> given in #git. This patch (part 2) adds the hint into the status\n> output. A bit of restructuring appears in the initial patch.\n>\n> This is merely an RFC, I am not sure whether I like it myself :-).\n\nWhile I think the patch means well, I personally think that the output is\nalready too chatty with these \"friendly hints\" about add/rm/reset.  After\nthis series, will we be adding 'use \"git checkout HEAD -- <path>\" to go\nback to the state of the latest commit', and then \"if you want to stage\nonly part of the change, use \"git add -i <path>\"?  \"To temporarily remove\nthe change use \"git stash\"?\n\nI would agree that \"hint is often given in #git\" is an indication that\npeople do not know \"git checkout\" to check out the path from the index to\nget rid of the change.  I further suspect that \"I modified my file and git\nstatus says 'Changed but not updated'; what should I do\" may not be asked\noften anymore, which might owe the hint we have in status output.  Even\nthen, I do not necessarily agree that the status output (yes, I am also\nquestioning the existing hints as well) is the best place to teach these\npeople.\n\nThe approach would lead to insanely long output that reproduces the user\nmanual, and we should draw the line somewhere.  As I said, I suspect that\nwhat we say is already too chatty.\n"},{"id":"90021","messageId":"B391BF4E-22D3-4083-8DDC-CF5823467813@frim.nl","threadId":"15414","inReplyTo":"7vtzcrk1wt.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC PATCH 0/2] Teach how to discard changes in the working directory","fromName":"Pieter de Bie","fromEmail":"pieter@frim.nl","sentAt":"2008-09-07T23:09:05Z","receivedAt":"2008-09-07T23:09:05Z","isPatch":true,"sender":{"key":"pieter@frim.nl","avatar":null},"body":"\nOn 8 sep 2008, at 00:48, Junio C Hamano wrote:\n\n> I would agree that \"hint is often given in #git\" is an indication that\n> people do not know \"git checkout\" to check out the path from the  \n> index to\n> get rid of the change.  I further suspect that \"I modified my file  \n> and git\n> status says 'Changed but not updated'; what should I do\" may not be  \n> asked\n> often anymore, which might owe the hint we have in status output.   \n> Even\n> then, I do not necessarily agree that the status output (yes, I am  \n> also\n> questioning the existing hints as well) is the best place to teach  \n> these\n> people.\n\nYes, this seems unclear to a lot of people. How about a small and  \nfocused\nman-page or similar to help people explain the differences between the\nworking directory, the index and HEAD? Then we can just add something\nlike\n\n\tIf you are unsure what to do, run `git help stage-changes`\n\nor so. This would differ from the git-commit man-page in that there is\nless clutter and most likely contains the information the user needs\nat the top of the page.\n\n- Pieter\n"},{"id":"90023","messageId":"7vprnfjzwf.fsf@gitster.siamese.dyndns.org","threadId":"15414","inReplyTo":"7vtzcrk1wt.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC PATCH 0/2] Teach how to discard changes in the working directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-07T23:32:16Z","receivedAt":"2008-09-07T23:32:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I would agree that \"hint is often given in #git\" is an indication that\n> people do not know \"git checkout\" to check out the path from the index to\n> get rid of the change.  I further suspect that \"I modified my file and git\n> status says 'Changed but not updated'; what should I do\" may not be asked\n> often anymore, which might owe the hint we have in status output.  Even\n> then, I do not necessarily agree that the status output (yes, I am also\n> questioning the existing hints as well) is the best place to teach these\n> people.\n>\n> The approach would lead to insanely long output that reproduces the user\n> manual, and we should draw the line somewhere.  As I said, I suspect that\n> what we say is already too chatty.\n\nHaving said all that, I'll queue them to see what other people think.\n"}]}