Advice on checkout dirty files
cover Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The new advice follows the same patterns established by existing advice functions such as advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice key
Arsh Srivastava (1):
advice: add stashBeforeCheckout advice for dirty branch switches
Junio C Hamano (1):
The 13th batch
K Jayatheerth (1):
repo: remove unnecessary variable shadow
LorenzoPegorari (2):
diff: handle ANSI escape codes in prefix when calculating diffstat
width
t4052: test for diffstat width when prefix contains ANSI escape codes
Documentation/RelNotes/2.54.0.adoc | 14 +++++++++++++ Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++ advice.h | 2 ++ builtin/repo.c | 1 - diff.c | 12 ++++------- t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 9 deletions(-)
base-commit: 3fe08b8fd1f7731edabeab8138547ec88d6407de
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
Pull-Request: https://github.com/git/git/pull/2233
Signature · 1 line
gitgitgadget
PATCH 1/5 diff: handle ANSI escape codes in prefix when calculating diffstat width
From: LorenzoPegorari <[email protected]>
The diffstat width is calculated by taking the terminal width and incorrectly subtracting the strlen() of line_prefix, instead of the actual display width of line_prefix, which may contain ANSI escape codes (e.g., ANSI-colored strings in log --graph --stat).
Utilize the display width instead, obtained via utf8_strnwidth() with the flag skip_ansi.
--- diff.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff.c +4 -8
@@ -2756,7 +2756,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) count = i;/* where we can stop scanning in data->files[] */ /* -* We have width = stat_width or term_columns() columns total. +* We have width = stat_width or term_columns() columns total minus the +* length of line_prefix skipping ANSI escape codes to get the display +* width (e.g., skip ANSI-colored strings in "log --graph --stat"). * We want a maximum of min(max_len, stat_name_width) for the name part. * We want a maximum of min(max_change, stat_graph_width) for the +- part. * We also need 1 for " " and 4 + decimal_width(max_change)
@@ -2783,14 +2785,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)* separators and this message, this message will "overflow" * making the line longer than the maximum width. */ - -/* -* NEEDSWORK: line_prefix is often used for "log --graph" output -* and contains ANSI-colored string. utf8_strnwidth() should be -* used to correctly count the display width instead of strlen(). -*/ if (options->stat_width ==-1 ) - width =term_columns () -strlen (line_prefix); + width =term_columns () -utf8_strnwidth (line_prefix,strlen (line_prefix),1 );else width = options->stat_width ? options->stat_width :80 ; number_width = decimal_width(max_change) > number_width ?
Signature · 1 line
gitgitgadget
PATCH 2/5 t4052: test for diffstat width when prefix contains ANSI escape codes
In reply to Arsh Srivastava via GitGitGadgetFrom: LorenzoPegorari <[email protected]>
Add test checking the calculation of the diffstat display width when the line_prefix, which is text that goes before the diffstat, contains ANSI escape codes.
This situation happens, for example, when git log --stat --graph is executed:
* --stat will create a diffstat for each commit
* --graph will stuff line_prefix with the graph portion of the log, which contains ANSI escape codes to color the text
--- t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
t/t4052-stat-output.sh +32 -0
@@ -413,4 +413,36 @@ test_expect_success 'merge --stat respects COLUMNS with long name' ' test_cmp expect actual ' +# We want git-log to print only 1 commit containing a single branch graph and a +# diffstat (the diffstat display width, when not manually set through the +# option "--stat-width", will be automatically calculated). +# The diffstat will be only one file, with a placeholder FILENAME, that, with +# enough terminal display width, will contain the following line: +# "<RED>|<RESET> ${FILENAME} | 0" +# where "<RED>" and "<RESET>" are ANSI escape codes to color the text. +# To calculate the minimium terminal display width MIN_TERM_WIDTH so that the +# FILENAME in the diffstat will not be shortened, we take the FILENAME length +# and add 9 to it. +# To check if the diffstat width, when the line_prefix (the "<RED>|<RESET>" of +# the graph) contains ANSI escape codes (the ANSI escape codes to color the +# text), is calculated correctly, we: +# 1. check if it contains the line defined before when using MIN_TERM_WIDTH +# 2. check if it contains the line defined before, but with the FILENAME +# shortened by only one character, when using MIN_TERM_WIDTH - 1 + +test_expect_success 'diffstat where line_prefix contains ANSI escape codes is correct width' ' + FILENAME="placeholder-text-placeholder-text" && + FILENAME_TRIMMED="...eholder-text-placeholder-text" && + MIN_TERM_WIDTH=$((${#FILENAME} + 9)) && + test_config color.diff always && + git commit --allow-empty --allow-empty-message && + >${FILENAME} && + git add ${FILENAME} && + git commit --allow-empty-message && + COLUMNS=$((MIN_TERM_WIDTH)) git log --graph --stat -n1 | test_decode_color >out && + test_grep "<RED>|<RESET> ${FILENAME} | 0" out && + COLUMNS=$((MIN_TERM_WIDTH - 1)) git log --graph --stat -n1 | test_decode_color >out && + test_grep "<RED>|<RESET> ${FILENAME_TRIMMED} | 0" out +' + test_done
Signature · 1 line
gitgitgadget
PATCH 3/5 repo: remove unnecessary variable shadow
In reply to Arsh Srivastava via GitGitGadgetFrom: K Jayatheerth <[email protected]>
Avoid redeclaring entry inside the conditional block, removing unnecessary variable shadowing and improving code clarity without changing behavior.
--- builtin/repo.c | 1 - 1 file changed, 1 deletion(-)
builtin/repo.c +0 -1
@@ -445,7 +445,6 @@ static void stats_table_print_structure(const struct stats_table *table)const char *unit ="" ;if (entry) { -struct stats_table_entry *entry = item->util; value = entry->value;if (entry->unit) unit = entry->unit;
Signature · 1 line
gitgitgadget
PATCH 4/5 The 13th batch
In reply to Arsh Srivastava via GitGitGadgetFrom: Junio C Hamano <[email protected]>
--- Documentation/RelNotes/2.54.0.adoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/RelNotes/2.54.0.adoc +14 -0
@@ -60,6 +60,10 @@ UI, Workflows & Features * "git config list" is taught to show the values interpreted for specific type with "--type=<X>" option. + * "git add <submodule>" has been taught to honor + submodule.<name>.ignore that is set to "all" (and requires "git add + -f" to override it). + Performance, Internal Implementation, Development Support etc. --------------------------------------------------------------
@@ -143,6 +147,11 @@ Performance, Internal Implementation, Development Support etc. were kept track of by a single global variable in-core, which has been corrected by moving it to per-repository data structure. + * Use the hook API to replace ad-hoc invocation of hook scripts via + the run_command() API. + + * Code refactoring around refs-for-each-* API functions. + Fixes since v2.53 -----------------
@@ -234,6 +243,10 @@ Fixes since v2.53 to access pack data by "fsck" has been updated to avoid this. (merge 13eb65d366 ps/fsck-stream-from-the-right-object-instance later to maint). + * "git log --graph --stat" did not count the display width of colored + graph part of its own output correctly, which has been corrected. + (merge 064b869efc lp/diff-stat-utf8-display-width-fix later to maint). + * Other code cleanup, docfix, build fix, etc. (merge d79fff4a11 jk/remote-tracking-ref-leakfix later to maint). (merge 7a747f972d dd/t5403-modernise later to maint).
@@ -264,3 +277,4 @@ Fixes since v2.53 (merge ed84bc1c0d kh/doc-patch-id-4 later to maint). (merge 7451864bfa sc/pack-redundant-leakfix later to maint). (merge f87593ab1a cx/fetch-display-ubfix later to maint). + (merge a66c8c7f91 jk/repo-structure-cleanup later to maint).
Signature · 1 line
gitgitgadget
PATCH 5/5 advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists the
affected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
The advice follows existing patterns established by advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
--- Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Documentation/config/advice.adoc +5 -0
@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +27 -0
@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}
advice.h +2 -0
@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
Signature · 1 line
gitgitgadget
Hi Arsh
Quoted 5 lines · Arsh Srivastava via GitGitGadget
This is my submission for microproject [GSOC]
This patch adds a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
If the intent is for the user to carry over the changes to the new branch then recommending "git checkout -m" might be more convenient rather than having to stash, checkout and unstash as three separate steps.
Something seems to have gone awry with your branch as there are other patches in this series. You should rebase your branch onto the upstream master branch with
git rebase --onto origin/master HEAD^
and then when you push it double check how many commits there are in the summary of the pull request before submitting.
Thanks
Phillip
Quoted 46 lines
The new advice follows the same patterns established by existing advice functions such as
advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice keySigned-off-by Arsh Srivastava [email protected]Arsh Srivastava (1):
advice: add stashBeforeCheckout advice for dirty branch switchesJunio C Hamano (1):
The 13th batchK Jayatheerth (1):
repo: remove unnecessary variable shadowLorenzoPegorari (2):
diff: handle ANSI escape codes in prefix when calculating diffstat
width
t4052: test for diffstat width when prefix contains ANSI escape codesDocumentation/RelNotes/2.54.0.adoc | 14 +++++++++++++ Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++ advice.h | 2 ++ builtin/repo.c | 1 - diff.c | 12 ++++------- t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 9 deletions(-)base-commit:
3fe08b8fd1f7731edabeab8138547ec88d6407de
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
Pull-Request: https://github.com/git/git/pull/2233
Thank you so much for the advice I will
Quoted 1 line
rebase my file’s pointer head
And just wanted to know what do you recommend should be my changed approach for me over this pr to make that function useful
Quoted 74 lines · Phillip Wood
Hi Arsh
Quoted 5 lines · Arsh Srivastava via GitGitGadget
This is my submission for microproject [GSOC]
This patch adds a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto help users when they attempt to switch branches with local modifications that would be overwritten by the operation.If the intent is for the user to carry over the changes to the new branch then recommending "git checkout -m" might be more convenient rather than having to stash, checkout and unstash as three separate steps.
Something seems to have gone awry with your branch as there are other patches in this series. You should rebase your branch onto the upstream master branch with
git rebase --onto origin/master HEAD^and then when you push it double check how many commits there are in the summary of the pull request before submitting.
Thanks
Phillip
Quoted 46 lines
The new advice follows the same patterns established by existing advice functions such as
advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice keySigned-off-by Arsh Srivastava [email protected]Arsh Srivastava (1):
advice: add stashBeforeCheckout advice for dirty branch switchesJunio C Hamano (1):
The 13th batchK Jayatheerth (1):
repo: remove unnecessary variable shadowLorenzoPegorari (2):
diff: handle ANSI escape codes in prefix when calculating diffstat
width
t4052: test for diffstat width when prefix contains ANSI escape codesDocumentation/RelNotes/2.54.0.adoc | 14 +++++++++++++ Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++ advice.h | 2 ++ builtin/repo.c | 1 - diff.c | 12 ++++------- t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 9 deletions(-)base-commit:
3fe08b8fd1f7731edabeab8138547ec88d6407de
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
Pull-Request: https://github.com/git/git/pull/2233
Hi,
Thank you for the feedback!
That's a great point. Using "git checkout -m" is indeed more convenient when the user wants to carry their changes over to the new branch, as it merges the local modifications into the new branch in a single step rather than requiring stash, checkout, and unstash separately.
I will update the advice message to mention "git checkout -m" as the primary suggestion when the intent is to carry changes over, and keep git stash push/pop as an alternative for when the user wants to temporarily set changes aside.
Will send a v2 shortly.
PATCH v2 1/1 advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists the
affected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
The advice follows existing patterns established by advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The new advice follows the same patterns established by existing advice functions such as advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add > "stashBeforeCheckout" to advice_setting[] and implement > advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v2
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v1:
1: 0ed992956e < -: ---------- diff: handle ANSI escape codes in prefix when calculating diffstat width 2: c70043a2c0 < -: ---------- t4052: test for diffstat width when prefix contains ANSI escape codes 3: 185356a454 < -: ---------- repo: remove unnecessary variable shadow 4: acebdd714b < -: ---------- The 13th batch 5: 9ec447e3cb = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Documentation/config/advice.adoc +5 -0
@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +27 -0
@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}
advice.h +2 -0
@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Signature · 1 line
gitgitgadget
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to a message not in the archiveI have as you mentioned changed
Quoted 2 lines
Rebased my files pointer
Changed advice to git checkout -m
Thank you
Quoted 155 lines · Arsh Srivastava
I have as you mentioned changed
Quoted 2 lines
Rebased my files pointer
Changed advice to git checkout -mThank you
Signed-off-by Arsh Srivastava <[email protected]>Quoted 146 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txtThe advice follows existing patterns established by
advise_on_updating_sparse_paths()and can be silenced with:git config set advice.stashBeforeCheckout false
Signed-off-by Arsh Srivastava <[email protected]>---
Advice on checkout dirty filesThis is my submission for microproject [GSOC]
This patch adds a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto help users when they attempt to switch branches with local modifications that would be overwritten by the operation.The new advice follows the same patterns established by existing advice functions such as
advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
>
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add > "stashBeforeCheckout" to advice_setting[] and implement >advise_on_checkout_dirty_files()function
>Documentation/config/advice.adoc: document the new advice keySigned-off-by Arsh Srivastava [email protected]Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v2
Pull-Request: https://github.com/git/git/pull/2233Range-diff vs v1:
1: 0ed992956e < -: ---------- diff: handle ANSI escape codes in prefix when calculating diffstat width 2: c70043a2c0 < -: ---------- t4052: test for diffstat width when prefix contains ANSI escape codes 3: 185356a454 < -: ---------- repo: remove unnecessary variable shadow 4: acebdd714b < -: ---------- The 13th batch 5: 9ec447e3cb = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switchesDocumentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +27
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}advice.h +2
-0@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */ base-commit:
d181b9354cf85b44455ce3ca9e6af0b9559e0ae2--
gitgitgadget
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh Srivastava via GitGitGadgetQuoted 13 lines · Arsh Srivastava via GitGitGadget
advice.c +1
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 317
Quoted 5 lines
advice.c +2
-0@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list)
Huh. So this patch wires up a new function and advice, but we don't ever seem to use it. Am I missing something?
Patrick
v3 cover Advice on checkout dirty files
In reply to Arsh Srivastava via GitGitGadgetThis is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The new advice follows the same patterns established by existing advice functions such as advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice key
Arsh Srivastava (2):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
Documentation/config/advice.adoc | 5 +++++ advice.c | 20 ++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 27 insertions(+)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v3
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v2:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches -: ---------- > 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
Signature · 1 line
gitgitgadget
PATCH v3 1/2 advice: add stashBeforeCheckout advice for dirty branch switches
From: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists the
affected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
The advice follows existing patterns established by advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
--- Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Documentation/config/advice.adoc +5 -0
@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +27 -0
@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}
advice.h +2 -0
@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
Signature · 1 line
gitgitgadget
PATCH v3 2/2 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
--- advice.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
advice.c +3 -10
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)fprintf (stderr,"\t%s\n" , item->string);advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , -_ ("You can save your local changes before switching by running:\n" +_ ("To carry your local changes over to the new branch, use:\n" "\n" -"\tgit stash push\n" -"\n" -"Then restore them after switching with:\n" -"\n" -"\tgit stash pop\n" -"\n" -"Or to discard your local changes, use:\n" -"\n" -"\tgit checkout -- <file>" )); +"\tgit checkout -m <branch>\n" + )); }
Signature · 1 line
gitgitgadget
Quoted 3 lines · Phillip Wood
If the intent is for the user to carry over the changes to the new branch then recommending "git checkout -m" might be more convenient rather than having to stash, checkout and unstash as three separate steps.
I personally would not recommend pushing "-m" to new people without explaining its ramifications, though.
If "git stash pop" fails while a commit different from the original is checked out, the working tree will get conflicts for you to resolve, and that is the same as "git checkout -m". But the conflict may turn out to be too complex that you might not be able to cleanly resolve.
With a "git stash pop" that gets interrupted by a conflict, the stash entry is not removed from the stash, so there is a clean recourse to "git reset --hard" away the conflict and attempting to unstash (either to the same commit or to a different base).
With "git checkout -m", on the other hand, there is no such recourse. The conflicted working tree with the unmerged index is all you get, and you get only a single chance to resolve it correctly.
So...
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Patrick SteinhardtThank you so much for looking into my PR and i believe advice.h is used in the add.c file. And advice really helps young developers understand what's wrong in their files because navigating git and trying to find solutions is very difficult, causing them to go to ai models making them copy pasting machines.
Quoted 25 lines · Patrick Steinhardt
Quoted 13 lines · Arsh Srivastava via GitGitGadget
advice.c +1
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 317
Quoted 5 lines
advice.c +2
-0@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list)Huh. So this patch wires up a new function and advice, but we don't ever seem to use it. Am I missing something?
Patrick
As per the recommendation of Phillip Wood <[email protected]> I have changed my files and added git checkout -m after understanding its significance :)
Quoted 28 lines · Junio C Hamano
Quoted 3 lines · Phillip Wood
If the intent is for the user to carry over the changes to the new branch then recommending "git checkout -m" might be more convenient rather than having to stash, checkout and unstash as three separate steps.
I personally would not recommend pushing "-m" to new people without explaining its ramifications, though.
If "git stash pop" fails while a commit different from the original is checked out, the working tree will get conflicts for you to resolve, and that is the same as "git checkout -m". But the conflict may turn out to be too complex that you might not be able to cleanly resolve.
With a "git stash pop" that gets interrupted by a conflict, the stash entry is not removed from the stash, so there is a clean recourse to "git reset --hard" away the conflict and attempting to unstash (either to the same commit or to a different base).
With "git checkout -m", on the other hand, there is no such recourse. The conflicted working tree with the unmerged index is all you get, and you get only a single chance to resolve it correctly.
So...
Re: [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh Srivastava via GitGitGadgetThank you so much for looking into my PR and i believe
Quoted 2 lines
advice.his used in theadd.cfile.
And advice really helps young developers
understand what's wrong in their files because navigating git and trying to find solutions is very difficult,
Quoted 1 line
causing them to go to ai models making them copy pasting machines.
Quoted 106 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txtThe advice follows existing patterns established by
advise_on_updating_sparse_paths()and can be silenced with:git config set advice.stashBeforeCheckout false
Signed-off-by Arsh Srivastava <[email protected]>--- Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +27
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}advice.h +2
-1@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */ --gitgitgadget
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh SrivastavaQuoted 24 lines · Arsh Srivastava
Quoted 14 lines · Patrick Steinhardt
Quoted 13 lines · Arsh Srivastava via GitGitGadget
advice.c +1
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)Quoted 8 lines
advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 317
Quoted 5 lines
advice.c +2
-0"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list)Huh. So this patch wires up a new function and advice, but we don't ever seem to use it. Am I missing something?
Quoted 5 lines
Thank you so much for looking into my PR and i believe
advice.his used in theadd.cfile. And advice really helps young developers understand what's wrong in their files because navigating git and trying to find solutions is very difficult, causing them to go to ai models making them copy pasting machines.
(Please note that we prefer bottom posting on this mailing list, where your answer goes below the quoted context.)
It is used in "add.c", but not magically so. The function that you have introduced is the only site that uses the new advice, but the function is never called as far as I can see. So ultimately, the proposed change does not have any effect on the user-observable behaviour.
Patrick
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh Srivastava via GitGitGadgetQuoted 6 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
Quoted 7 lines
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
Nit: Did you mean to add bullet point here? '>' is generally used to quote text. Perhaps use '-' or '*'.
[snip]
Quoted 6 lines
Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Hmm. Shouldn't there be changes which actually call the newly introduced function? Also shouldn't there be tests added?
Documentation/config/advice.adoc all advice messages. · line 133
Quoted 13 lines
Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching.
Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
In one of my repos:
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
❯ echo "aldjf" >> LICENSE
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory)
modified: LICENSE
no changes added to commit (use "git add" and/or "git commit -a")
❯ git checkout 0-1-stable
error: Your local changes to the following files would be overwritten by checkout:
LICENSE
Please commit your changes or stash them before you switch branches. Aborting
So won't this simply be duplicating the same message?
Quoted 35 lines
Documentation/config/advice.adoc +0
-0statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +17
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT, + _("You can save your local changes before switching by running:\n" + "\n"
advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 341
Quoted 10 lines
advice.c +10
-0+"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" + "\tgit checkout -- <file>")); +}
This doesn't seem to be formatted with tabs.
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 2 lines · Karthik Nayak
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?
Thank you for the detailed review. You are correct, the existing message in unpack-trees.c already handles this case and my patch duplicates it. I also acknowledge the other issues raised:
- The newly introduced function was never called anywhere in the codebase
- No tests were added
- The bullet points in the commit message used '>' instead of '-' or '*'
- The advice message was not formatted with tabs
Rather than duplicating the existing behaviour, I think the better approach would be to enhance the existing message in unpack-trees.c to also mention 'git checkout -m' as an option for users who want to carry their local changes over to the new branch, since the current message only says "commit or stash" without mentioning that option.
I will rework the patch in that direction and send a v4.
Quoted 125 lines · Karthik Nayak
Quoted 6 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.Quoted 7 lines
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txtNit: Did you mean to add bullet point here? '>' is generally used to quote text. Perhaps use '-' or '*'.
[snip]
Quoted 6 lines
Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)Hmm. Shouldn't there be changes which actually call the newly introduced function? Also shouldn't there be tests added?
Documentation/config/advice.adoc all advice messages. · line 133
Quoted 13 lines
Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching.Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this?In one of my repos:
❯ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
❯ echo "aldjf" >> LICENSE
❯ git status
On branch master
Your branch is up to date with 'origin/master'.Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory)
modified: LICENSEno changes added to commit (use "git add" and/or "git commit -a")
❯ git checkout 0-1-stable
error: Your local changes to the following files would be overwritten by checkout:
LICENSE
Please commit your changes or stash them before you switch branches. AbortingSo won't this simply be duplicating the same message?
Quoted 35 lines
Documentation/config/advice.adoc +0
-0statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +17
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT, + _("You can save your local changes before switching by running:\n" + "\n"advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 341
Quoted 10 lines
advice.c +10
-0+"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" + "\tgit checkout -- <file>")); +}This doesn't seem to be formatted with tabs.
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 4 lines · Patrick Steinhardt
It is used in "
add.c", but not magically so. The function that you have introduced is the only site that uses the new advice, but the function is never called as far as I can see. So ultimately, the proposed change does not have any effect on the user-observable behaviour.
Thank you for the correction and for the bottom-posting reminder.
You are right. The function advise_on_checkout_dirty_files() is defined but never called anywhere, so the patch has no user-observable effect. I also looked into the existing behaviour more carefully and found that unpack-trees.c already handles this case and prints a message telling the user to commit or stash their changes before switching branches.
So the patch as written is both incomplete and duplicates existing behaviour. I will rework it in v3 to instead enhance the existing message in unpack-trees.c to also mention 'git checkout -m' for users who want to carry their local changes over to the new branch.
Quoted 154 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 2 lines · Karthik Nayak
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?Thank you for the detailed review. You are correct, the existing message in
unpack-trees.calready handles this case and my patch duplicates it. I also acknowledge the other issues raised:- The newly introduced function was never called anywhere in the codebase
- No tests were added
- The bullet points in the commit message used '>' instead of '-' or '*'
- The advice message was not formatted with tabsRather than duplicating the existing behaviour, I think the better approach would be to enhance the existing message in
unpack-trees.cto also mention 'git checkout -m' as an option for users who want to carry their local changes over to the new branch, since the current message only says "commit or stash" without mentioning that option.I will rework the patch in that direction and send a v4.
Signed-off-by Arsh Srivastava <[email protected]>Quoted 125 lines · Karthik Nayak
Quoted 6 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.Quoted 7 lines
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txtNit: Did you mean to add bullet point here? '>' is generally used to quote text. Perhaps use '-' or '*'.
[snip]
Quoted 6 lines
Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)Hmm. Shouldn't there be changes which actually call the newly introduced function? Also shouldn't there be tests added?
Documentation/config/advice.adoc all advice messages. · line 133
Quoted 13 lines
Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching.Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this?In one of my repos:
❯ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
❯ echo "aldjf" >> LICENSE
❯ git status
On branch master
Your branch is up to date with 'origin/master'.Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory)
modified: LICENSEno changes added to commit (use "git add" and/or "git commit -a")
❯ git checkout 0-1-stable
error: Your local changes to the following files would be overwritten by checkout:
LICENSE
Please commit your changes or stash them before you switch branches. AbortingSo won't this simply be duplicating the same message?
Quoted 35 lines
Documentation/config/advice.adoc +0
-0statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +17
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT, + _("You can save your local changes before switching by running:\n" + "\n"advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 341
Quoted 10 lines
advice.c +10
-0+"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" + "\tgit checkout -- <file>")); +}This doesn't seem to be formatted with tabs.
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh SrivastavaSubject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 4 lines · Patrick Steinhardt
It is used in "
add.c", but not magically so. The function that you have introduced is the only site that uses the new advice, but the function is never called as far as I can see. So ultimately, the proposed change does not have any effect on the user-observable behaviour.
Thank you for the correction and for the bottom-posting reminder.
You are right. The function advise_on_checkout_dirty_files() is defined but never called anywhere, so the patch has no user-observable effect. I also looked into the existing behaviour more carefully and found that unpack-trees.c already handles this case and prints a message telling the user to commit or stash their changes before switching branches.
So the patch as written is both incomplete and duplicates existing behaviour. I will rework it in v4 to instead enhance the existing message in unpack-trees.c to also mention 'git checkout -m' for users who want to carry their local changes over to the new branch.
Quoted 154 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 2 lines · Karthik Nayak
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?Thank you for the detailed review. You are correct, the existing message in
unpack-trees.calready handles this case and my patch duplicates it. I also acknowledge the other issues raised:- The newly introduced function was never called anywhere in the codebase
- No tests were added
- The bullet points in the commit message used '>' instead of '-' or '*'
- The advice message was not formatted with tabsRather than duplicating the existing behaviour, I think the better approach would be to enhance the existing message in
unpack-trees.cto also mention 'git checkout -m' as an option for users who want to carry their local changes over to the new branch, since the current message only says "commit or stash" without mentioning that option.I will rework the patch in that direction and send a v4.
Signed-off-by Arsh Srivastava <[email protected]>Quoted 125 lines · Karthik Nayak
Quoted 6 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
Add a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.Quoted 7 lines
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists theaffected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txtNit: Did you mean to add bullet point here? '>' is generally used to quote text. Perhaps use '-' or '*'.
[snip]
Quoted 6 lines
Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)Hmm. Shouldn't there be changes which actually call the newly introduced function? Also shouldn't there be tests added?
Documentation/config/advice.adoc all advice messages. · line 133
Quoted 13 lines
Documentation/config/advice.adoc +5
-0@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching.Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this?In one of my repos:
❯ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
❯ echo "aldjf" >> LICENSE
❯ git status
On branch master
Your branch is up to date with 'origin/master'.Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory)
modified: LICENSEno changes added to commit (use "git add" and/or "git commit -a")
❯ git checkout 0-1-stable
error: Your local changes to the following files would be overwritten by checkout:
LICENSE
Please commit your changes or stash them before you switch branches. AbortingSo won't this simply be duplicating the same message?
Quoted 35 lines
Documentation/config/advice.adoc +0
-0statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,advice.c +17
-0@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT, + _("You can save your local changes before switching by running:\n" + "\n"advice.c void advise_on_moving_dirty_path(struct string_list *pathspec_list) · line 341
Quoted 10 lines
advice.c +10
-0+"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" + "\tgit checkout -- <file>")); +}This doesn't seem to be formatted with tabs.
Quoted 3 lines · Arsh Srivastava
As per the recommendation of Phillip Wood <[email protected]> I have changed my files and added git checkout -m after understanding its significance :)
It is a given that you as the author of the patch understand it. What I meant was that the users who get the recommendation need to be told about the potential issues.
Quoted 2 lines · Junio C Hamano
It is understood as author that I understand.
It is the users who need to understand.
As informed by Karthik Nayak <[email protected]> and Patrick Steinhardt <[email protected]>.
My PR seemed to have redundancy for which I will create a v4 for my PR removing it and giving it proper description for users to understand.
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Arsh Srivastava
As per the recommendation of Phillip Wood <[email protected]> I have changed my files and added git checkout -m after understanding its significance :)
It is a given that you as the author of the patch understand it. What I meant was that the users who get the recommendation need to be told about the potential issues.
Quoted 3 lines · Junio C Hamano
It is understood as author that I understand.
It is the users who need to understand.
Potential risks for the user.
As informed by Karthik Nayak <[email protected]> and Patrick Steinhardt <[email protected]>.
My PR seemed to have redundancy for which I will create a v4 for my PR removing it and giving it proper description for users to understand the possible risks of using -m.
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Arsh Srivastava
As per the recommendation of Phillip Wood <[email protected]> I have changed my files and added git checkout -m after understanding its significance :)
It is a given that you as the author of the patch understand it. What I meant was that the users who get the recommendation need to be told about the potential issues.
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh SrivastavaQuoted 5 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Karthik Nayak <[email protected]> writes:
Quoted 8 lines
Quoted 2 lines
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?Thank you for the detailed review. You are correct, the existing message
...
I will rework the patch in that direction and send a v4.Signed-off-by Arsh Srivastava <[email protected]>
Just a comment by a bystander, but it confuses me quite a lot to see in-body "Subject:" and "Sign-off" in a message that is *not* a patch at all. What are you signing off with this signature?
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 2 lines · Karthik Nayak
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?Thank you for the detailed review. You are correct, the existing message
...
I will rework the patch in that direction and send a v4.
Quoted 5 lines
Quoted 1 line
Signed-off-by Arsh Srivastava <[email protected]>Just a comment by a bystander, but it confuses me quite a lot to see in-body "Subject:" and "Sign-off" in a message that is *not* a patch at all. What are you signing off with this signature?
Tangentially, I know that b4 adds a "Sign-off" to the cover message.
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Arsh SrivastavaQuoted 18 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 4 lines · Patrick Steinhardt
It is used in "
add.c", but not magically so. The function that you have introduced is the only site that uses the new advice, but the function is never called as far as I can see. So ultimately, the proposed change does not have any effect on the user-observable behaviour.Thank you for the correction and for the bottom-posting reminder.
You are right. The function
advise_on_checkout_dirty_files()is defined but never called anywhere, so the patch has no user-observable effect. I also looked into the existing behaviour more carefully and found thatunpack-trees.calready handles this case and prints a message telling the user to commit or stash their changes before switching branches.
Quoted 5 lines
So the patch as written is both incomplete and duplicates existing behaviour. I will rework it in v3 to instead enhance the existing message in
unpack-trees.cto also mention 'git checkout -m' for users who want to carry their local changes over to the new branch.
I must say that the patch itself and the responses seem like they're generated with LLMs. Our guidelines for AI usage within the Git project are laid out in 'Documentation/SubmittingPatches'.
For GSoC specifically, we have laid out our expectations here [1]. Please go through them.
[1]: https://git.github.io/General-Application-Information/
[snip]
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Junio C HamanoJunio C Hamano <[email protected]> writes
Quoted 1 line
Sign-off and Subject in body confuses
I thought writing sign-off was a necessity for my mail to be accepted
Quoted 20 lines · Junio C Hamano
Quoted 5 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Karthik Nayak <[email protected]> writes:
Quoted 8 lines
Quoted 2 lines
Doesn't '
ADVICE_COMMIT_BEFORE_MERGE' already do this? So won't this simply be duplicating the same message?Thank you for the detailed review. You are correct, the existing message
...
I will rework the patch in that direction and send a v4.Signed-off-by Arsh Srivastava <[email protected]>Just a comment by a bystander, but it confuses me quite a lot to see in-body "Subject:" and "Sign-off" in a message that is *not* a patch at all. What are you signing off with this signature?
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Karthik NayakKarthik Nayak <[email protected]> writes
Quoted 2 lines
Use of Ai in patches and messages
Suggest the documentation for the same
After reading the document carefully again , I understood my mistakes and I promise to not repeat it again while submitting future PR and commits.
I am deeply sorry for the mistakes I made and promise to never repeat them again including in submission of version 4 of my current PR
Quoted 37 lines · Karthik Nayak
Quoted 18 lines · Arsh Srivastava
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty branch switches
Quoted 4 lines · Patrick Steinhardt
It is used in "
add.c", but not magically so. The function that you have introduced is the only site that uses the new advice, but the function is never called as far as I can see. So ultimately, the proposed change does not have any effect on the user-observable behaviour.Thank you for the correction and for the bottom-posting reminder.
You are right. The function
advise_on_checkout_dirty_files()is defined but never called anywhere, so the patch has no user-observable effect. I also looked into the existing behaviour more carefully and found thatunpack-trees.calready handles this case and prints a message telling the user to commit or stash their changes before switching branches.Quoted 5 lines
So the patch as written is both incomplete and duplicates existing behaviour. I will rework it in v3 to instead enhance the existing message in
unpack-trees.cto also mention 'git checkout -m' for users who want to carry their local changes over to the new branch.I must say that the patch itself and the responses seem like they're generated with LLMs. Our guidelines for AI usage within the Git project are laid out in '
Documentation/SubmittingPatches'.For GSoC specifically, we have laid out our expectations here [1]. Please go through them.
[1]: https://git.github.io/General-Application-Information/
[snip]
v4 cover Advice on checkout dirty files
In reply to Arsh Srivastava via GitGitGadgetThis is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The new advice follows the same patterns established by existing advice functions such as advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice key
Arsh Srivastava (5):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
Updating tests and unpack-tress.c [GSOC]
File updation [GSOC]
t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v3:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC] -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
Signature · 1 line
gitgitgadget
PATCH v4 1/5 advice: add stashBeforeCheckout advice for dirty branch switches
From: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists the
affected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
The advice follows existing patterns established by advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
--- Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Documentation/config/advice.adoc +5 -0
@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +27 -0
@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}
advice.h +2 -0
@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
Signature · 1 line
gitgitgadget
PATCH v4 2/5 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
--- advice.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
advice.c +3 -10
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)fprintf (stderr,"\t%s\n" , item->string);advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , -_ ("You can save your local changes before switching by running:\n" +_ ("To carry your local changes over to the new branch, use:\n" "\n" -"\tgit stash push\n" -"\n" -"Then restore them after switching with:\n" -"\n" -"\tgit stash pop\n" -"\n" -"Or to discard your local changes, use:\n" -"\n" -"\tgit checkout -- <file>" )); +"\tgit checkout -m <branch>\n" + )); }
Signature · 1 line
gitgitgadget
PATCH v4 3/5 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
This comment is an extention to the already existing stash comment.
After the valuable insights given to me by git maintaniers. I removed the new function I introduced.
Added updated comment over the already existing function "setup_unpack_trees_porcelain" with "git checkout -m <branch>" and its repercussions
I have also mentioned the repercussions of using "-m".
--- Documentation/config/advice.adoc | 5 ----- advice.c | 20 -------------------- advice.h | 2 -- unpack-trees.c | 13 +++++++++++-- 4 files changed, 11 insertions(+), 29 deletions(-)
Documentation/config/advice.adoc +0 -5
@@ -126,11 +126,6 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. - stashBeforeCheckout:: - Shown when the user attempts to switch branches but has - local modifications that would be overwritten by the - operation, to suggest using linkgit:git-stash[1] to - save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +0 -20
@@ -81,7 +81,6 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, - [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } - -void advise_on_checkout_dirty_files (struct string_list *file_list) -{ -struct string_list_item *item; - -if (!file_list->nr) -return ; - -fprintf (stderr,_ ("The following files have local modifications that would\n" -"be overwritten by switching branches:\n" )); -for_each_string_list_item (item, file_list) -fprintf (stderr,"\t%s\n" , item->string); - -advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , -_ ("To carry your local changes over to the new branch, use:\n" -"\n" -"\tgit checkout -m <branch>\n" - )); -}
advice.h +0 -2
@@ -48,7 +48,6 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , -ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); -void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
unpack-trees.c +11 -2
@@ -128,8 +128,17 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,if (!strcmp (cmd,"checkout" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ?_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches." ) - :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" ); +"Please commit your changes or stash them before you switch branches.\n" +"Try using 'git checkout -m <branch>' for a quick fix. \n" +"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" +"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." + ) + :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches.\n" +"Try using 'git checkout -m <branch>' for a quick fix.\n" +"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" +"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." + );else if (!strcmp (cmd,"merge" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
Signature · 1 line
gitgitgadget
PATCH v4 4/5 Updating tests and unpack-tress.c [GSOC]
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
While submitting my previous commit found that
previous testcases weren't working properly
with my updates
So fixed the test updates and advice conflict issue.
--- t/t6439-merge-co-error-msgs.sh | 4 ++++ t/t7406-submodule-update.sh | 2 ++ unpack-trees.c | 6 +----- 3 files changed, 7 insertions(+), 5 deletions(-)
t/t6439-merge-co-error-msgs.sh +4 -0
@@ -77,6 +77,8 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
@@ -99,6 +101,8 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
t/t7406-submodule-update.sh +2 -0
@@ -212,6 +212,8 @@ test_expect_success 'submodule update should fail due to local changes' ' > error: Your local changes to the following files would be overwritten by checkout: > file > Please commit your changes or stash them before you switch branches. + > Try using '\''git checkout -m <branch>'\'' for a quick fix. + > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. > Aborting > fatal: Unable to checkout OID in submodule path '\''submodule'\'' EOF
unpack-trees.c +1 -5
@@ -134,11 +134,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." ) : _("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches.\n" -"Try using 'git checkout -m <branch>' for a quick fix.\n" -"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" -"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." - ); +"Please commit your changes or stash them before you switch branches." ); else if (!strcmp(cmd, "merge")) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
Signature · 1 line
gitgitgadget
PATCH v4 5/5 File updation [GSOC]
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
I have ran tests locally for this file
and tried to fix all the CI issues
Lets Hope it works
--- t/t6439-merge-co-error-msgs.sh | 6 ++++-- t/t7406-submodule-update.sh | 3 ++- unpack-trees.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)
t/t6439-merge-co-error-msgs.sh +4 -2
@@ -78,7 +78,8 @@ error: Your local changes to the following files would be overwritten by checkou rep/two Please commit your changes or stash them before you switch branches. Try using 'git checkout -m <branch>' for a quick fix. -Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
@@ -102,7 +103,8 @@ error: Your local changes to the following files would be overwritten by checkou rep/two Please commit your changes or stash them before you switch branches. Try using 'git checkout -m <branch>' for a quick fix. -Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
t/t7406-submodule-update.sh +2 -1
@@ -213,7 +213,8 @@ test_expect_success 'submodule update should fail due to local changes' ' > file > Please commit your changes or stash them before you switch branches. > Try using '\''git checkout -m <branch>'\'' for a quick fix. - > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. + > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. + > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. > Aborting > fatal: Unable to checkout OID in submodule path '\''submodule'\'' EOF
unpack-trees.c +1 -1
@@ -129,7 +129,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by checkout:\n%%s" "Please commit your changes or stash them before you switch branches.\n" - "Try using 'git checkout -m <branch>' for a quick fix. \n" + "Try using 'git checkout -m <branch>' for a quick fix.\n" "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." )
Signature · 1 line
gitgitgadget
Quoted 15 lines · Arsh Srivastava via GitGitGadget
This is my submission for microproject [GSOC]
This patch adds a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto help users when they attempt to switch branches with local modifications that would be overwritten by the operation.The new advice follows the same patterns established by existing advice functions such as
advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Quoted 8 lines
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice keySigned-off-by Arsh Srivastava [email protected]
Even though no developer is perfect, when you are presenting your updated work, armed with wisdom borrowed from your reviewers' comments on your earlier attempts, you are expected to take the opportunity to pretend to have written a series of patches that are perfect logical progression towards the final shape of the code without detours, change of plans, and fixing earlier mistakes made in the series.
Please do not throw a drunken-man's-walk series at us. For example, I see that [PATCH 3/5] literally removes what was added by earlier patches. This is not a place for you to show how you made wrong turns before arriving at the final shape of the code.
The final series accepted by the project will have to stay in our history for later developers to see in "git log" output to learn from, and a series being clean logical progression is a must for that to happen.
Also, what is "updation"? Is it a standard English word, or some dialect of an LLM origin?
Quoted 27 lines
Arsh Srivastava (5):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches[GSOC]unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
Updating tests andunpack-tress.c[GSOC]
File updation [GSOC]t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)base-commit:
d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
Pull-Request: https://github.com/git/git/pull/2233Range-diff vs v3:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC] -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
Junio C Hamano <[email protected]> writes :-
Quoted 4 lines
provide perfect logic not drunken-man's-walk series.
not a place for you to show how you made wrong turns before arriving at the final shape of the code. history for later developers to see in "git log" output to learn from
what is "updation"
Thank you so much for your feedback.
Again terribly sorry I will rebase my commit so that it has perfect progression. And updation is a noun first published in Oxford English Dictionary in 2018.
Quoted 75 lines · Junio C Hamano
Quoted 15 lines · Arsh Srivastava via GitGitGadget
This is my submission for microproject [GSOC]
This patch adds a new advice type
ADVICE_STASH_BEFORE_CHECKOUTto help users when they attempt to switch branches with local modifications that would be overwritten by the operation.The new advice follows the same patterns established by existing advice functions such as
advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Quoted 8 lines
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice keySigned-off-by Arsh Srivastava [email protected]Even though no developer is perfect, when you are presenting your updated work, armed with wisdom borrowed from your reviewers' comments on your earlier attempts, you are expected to take the opportunity to pretend to have written a series of patches that are perfect logical progression towards the final shape of the code without detours, change of plans, and fixing earlier mistakes made in the series.
Please do not throw a drunken-man's-walk series at us. For example, I see that [PATCH 3/5] literally removes what was added by earlier patches. This is not a place for you to show how you made wrong turns before arriving at the final shape of the code.
The final series accepted by the project will have to stay in our history for later developers to see in "git log" output to learn from, and a series being clean logical progression is a must for that to happen.
Also, what is "updation"? Is it a standard English word, or some dialect of an LLM origin?
Quoted 27 lines
Arsh Srivastava (5):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches[GSOC]unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
Updating tests andunpack-tress.c[GSOC]
File updation [GSOC]t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)base-commit:
d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
Pull-Request: https://github.com/git/git/pull/2233Range-diff vs v3:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC] -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
v5 cover Advice on checkout dirty files
In reply to Arsh Srivastava via GitGitGadgetThis is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The new advice follows the same patterns established by existing advice functions such as advise_on_updating_sparse_paths(). When triggered, it lists the affected files and suggests using git stash push/pop to save and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice key
Arsh Srivastava (3):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v5
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v4:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] 3: 4237b9667d ! 3: 1cc22f437e unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ advice.h: void NORETURN die_ff_impossible(void);
#endif /* ADVICE_H */
+ ## t/t6439-merge-co-error-msgs.sh ##
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. ++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. ++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+
+ ## t/t7406-submodule-update.sh ##
+@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ > error: Your local changes to the following files would be overwritten by checkout:
+ > file
+ > Please commit your changes or stash them before you switch branches.
++ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
++ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ > Aborting
+ > fatal: Unable to checkout OID in submodule path '\''submodule'\''
+ EOF
+
## unpack-trees.c ##
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix. \n"
++ "Try using 'git checkout -m <branch>' for a quick fix.\n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
-+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
-+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
-+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
-+ );
++ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
4: b25ea22410 < -: ---------- Updating tests and unpack-tress.c [GSOC] 5: 2ef7d5a3d6 < -: ---------- File updation [GSOC]
Signature · 1 line
gitgitgadget
PATCH v5 1/3 advice: add stashBeforeCheckout advice for dirty branch switches
From: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
This includes:
Quoted 3 lines
New
ADVICE_STASH_BEFORE_CHECKOUTenum value inadvice.hCorresponding "stashBeforeCheckout" entry in advice_setting[] Newadvise_on_checkout_dirty_files()function that lists the
affected files and suggests using git stash push/pop
Quoted 1 line
Documentation entry in
Documentation/config/advice.txt
The advice follows existing patterns established by advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
--- Documentation/config/advice.adoc | 5 +++++ advice.c | 27 +++++++++++++++++++++++++++ advice.h | 2 ++ 3 files changed, 34 insertions(+)
Documentation/config/advice.adoc +5 -0
@@ -126,6 +126,11 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. + stashBeforeCheckout:: + Shown when the user attempts to switch branches but has + local modifications that would be overwritten by the + operation, to suggest using linkgit:git-stash[1] to + save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +27 -0
@@ -81,6 +81,7 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } + +void advise_on_checkout_dirty_files (struct string_list *file_list) +{ +struct string_list_item *item; + +if (!file_list->nr) +return ; + +fprintf (stderr,_ ("The following files have local modifications that would\n" +"be overwritten by switching branches:\n" )); +for_each_string_list_item (item, file_list) +fprintf (stderr,"\t%s\n" , item->string); + +advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , +_ ("You can save your local changes before switching by running:\n" +"\n" +"\tgit stash push\n" +"\n" +"Then restore them after switching with:\n" +"\n" +"\tgit stash pop\n" +"\n" +"Or to discard your local changes, use:\n" +"\n" +"\tgit checkout -- <file>" )); +}
advice.h +2 -0
@@ -48,6 +48,7 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , +ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); +void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
Signature · 1 line
gitgitgadget
PATCH v5 2/3 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users when they attempt to switch branches with local modifications that would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
--- advice.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
advice.c +3 -10
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)fprintf (stderr,"\t%s\n" , item->string);advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , -_ ("You can save your local changes before switching by running:\n" +_ ("To carry your local changes over to the new branch, use:\n" "\n" -"\tgit stash push\n" -"\n" -"Then restore them after switching with:\n" -"\n" -"\tgit stash pop\n" -"\n" -"Or to discard your local changes, use:\n" -"\n" -"\tgit checkout -- <file>" )); +"\tgit checkout -m <branch>\n" + )); }
Signature · 1 line
gitgitgadget
PATCH v5 3/3 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
This comment is an extention to the already existing stash comment.
After the valuable insights given to me by git maintaniers. I removed the new function I introduced.
Added updated comment over the already existing function "setup_unpack_trees_porcelain" with "git checkout -m <branch>" and its repercussions
I have also mentioned the repercussions of using "-m".
--- Documentation/config/advice.adoc | 5 ----- advice.c | 20 -------------------- advice.h | 2 -- t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 6 files changed, 16 insertions(+), 29 deletions(-)
Documentation/config/advice.adoc +0 -5
@@ -126,11 +126,6 @@ all advice messages. Shown when a sparse index is expanded to a full index, which is likely due to an unexpected set of files existing outside of the sparse-checkout. - stashBeforeCheckout:: - Shown when the user attempts to switch branches but has - local modifications that would be overwritten by the - operation, to suggest using linkgit:git-stash[1] to - save changes before switching. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref,
advice.c +0 -20
@@ -81,7 +81,6 @@ static struct { [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" }, [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" }, [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" }, - [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" }, [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" }, [ADVICE_STATUS_HINTS] = { "statusHints" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)"* Use \"git add --sparse <paths>\" to update the index\n" "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); } - -void advise_on_checkout_dirty_files (struct string_list *file_list) -{ -struct string_list_item *item; - -if (!file_list->nr) -return ; - -fprintf (stderr,_ ("The following files have local modifications that would\n" -"be overwritten by switching branches:\n" )); -for_each_string_list_item (item, file_list) -fprintf (stderr,"\t%s\n" , item->string); - -advise_if_enabled (ADVICE_STASH_BEFORE_CHECKOUT , -_ ("To carry your local changes over to the new branch, use:\n" -"\n" -"\tgit checkout -m <branch>\n" - )); -}
advice.h +0 -2
@@ -48,7 +48,6 @@ enum advice_type {ADVICE_SET_UPSTREAM_FAILURE ,ADVICE_SKIPPED_CHERRY_PICKS ,ADVICE_SPARSE_INDEX_EXPANDED , -ADVICE_STASH_BEFORE_CHECKOUT ,ADVICE_STATUS_AHEAD_BEHIND_WARNING ,ADVICE_STATUS_HINTS , ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);void detach_advice (const char *new_name);void advise_on_moving_dirty_path (struct string_list *pathspec_list); -void advise_on_checkout_dirty_files (struct string_list *file_list);#endif /* ADVICE_H */
t/t6439-merge-co-error-msgs.sh +6 -0
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
t/t7406-submodule-update.sh +3 -0
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' ' > error: Your local changes to the following files would be overwritten by checkout: > file > Please commit your changes or stash them before you switch branches. + > Try using '\''git checkout -m <branch>'\'' for a quick fix. + > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. + > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. > Aborting > fatal: Unable to checkout OID in submodule path '\''submodule'\'' EOF
unpack-trees.c +7 -2
@@ -128,8 +128,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,if (!strcmp (cmd,"checkout" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ?_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches." ) - :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" ); +"Please commit your changes or stash them before you switch branches.\n" +"Try using 'git checkout -m <branch>' for a quick fix.\n" +"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" +"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." + ) + :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );else if (!strcmp (cmd,"merge" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
Signature · 1 line
gitgitgadget
Quoted 7 lines · Arsh Srivastava via GitGitGadget
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice key
Quoted 8 lines
Signed-off-by Arsh Srivastava [email protected]Arsh Srivastava (3):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches[GSOC]unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
I still see that [PATCH 3/3] literally removes what was added by earlier patches. ADVICE_STASH_BEFORE_CHECKOUT is added to advice.[ch] and stashBeforeCheckOut is added to Documentation/config/adivce.adoc in [1/3], and then they are removed in [3/3]. If your final solution does not involve such an advice, then do not even add it in an earlier patch, only to retract it and replace it with something else in a later patch. If the reason why that "something else" replaces the advice is because it is a better solution to the problem you initially started to solve than the advice message added in [1/3], then just go straight to that "something else", without adding and removing the advice mechanism.
That is what "perfect logical progression without detours, change of plans, and fixes earlier mistake" is about.
In other words, please do not throw a drunken-man's-walk series at us. Pretend to be a perfect developer.
The final series accepted by the project will have to stay in our history for later developers to see in "git log" output to learn from, and a series being clean logical progression is a must for that to happen.
Junio C Hamano <[email protected]> writes :
Quoted 5 lines
He still see 3 patches for a work that can be done by one. That is what "perfect logical progression without detours, change of plans, and fixes earlier mistake" is about.
please do not throw a drunken-man's-walk series at
us. Pretend to be a perfect developer
I understand now sorry for the inconvenience.
Your mail also specified the same thing but I was not able to truly grasp the essence of that mail.
Thank you for explaining it again to me, I now have clear understanding of what is expected from me.
I will create one single commit :) .
I also saw that git via git gadget forwards all my commits making it messy and not ideal.
I will make a clean single commit that will look perfect and wouldn't make such a messy commit history.
Quoted 42 lines · Junio C Hamano
Quoted 7 lines · Arsh Srivastava via GitGitGadget
Changes:
Quoted 4 lines
advice.h: addADVICE_STASH_BEFORE_CHECKOUTenum valueadvice.c: add "stashBeforeCheckout" to advice_setting[] and implementadvise_on_checkout_dirty_files()functionDocumentation/config/advice.adoc: document the new advice keyQuoted 8 lines
Signed-off-by Arsh Srivastava [email protected]Arsh Srivastava (3):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches[GSOC]unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussionsI still see that [PATCH 3/3] literally removes what was added by earlier patches.
ADVICE_STASH_BEFORE_CHECKOUTis added to advice.[ch] and stashBeforeCheckOut is added toDocumentation/config/adivce.adocin [1/3], and then they are removed in [3/3]. If your final solution does not involve such an advice, then do not even add it in an earlier patch, only to retract it and replace it with something else in a later patch. If the reason why that "something else" replaces the advice is because it is a better solution to the problem you initially started to solve than the advice message added in [1/3], then just go straight to that "something else", without adding and removing the advice mechanism.That is what "perfect logical progression without detours, change of plans, and fixes earlier mistake" is about.
In other words, please do not throw a drunken-man's-walk series at us. Pretend to be a perfect developer.
The final series accepted by the project will have to stay in our history for later developers to see in "git log" output to learn from, and a series being clean logical progression is a must for that to happen.
PATCH v6 1/1 unpack-trees: suggesting 'git checkout -m' with its repercussions
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
This comment is an extention to the already existing stash comment. Added updated comment over the already existing function "setup_unpack_trees_porcelain" with "git checkout -m" and its repercussions
I have also mentioned the repercussions of using "-m".
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and > checkout tests. t/t7406-submodule-update.sh: update expected output > for submodule checkout tests.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v6
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v5:
1: eb5639dbc3 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches 2: e88c851701 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] 3: 1cc22f437e ! 1: e0ba5fad82 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ Metadata
Author: Arsh Srivastava <[email protected]>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
+ unpack-trees: suggesting 'git checkout -m' with its repercussions
This comment is an extention to the already existing stash comment.
-
- After the valuable insights given to me by git maintaniers.
- I removed the new function I introduced.
Added updated comment over the already existing function
- "setup_unpack_trees_porcelain" with "git checkout -m <branch>"
+ "setup_unpack_trees_porcelain" with "git checkout -m"
and its repercussions
I have also mentioned the repercussions of using "-m".
- Signed-off-by: Arsh Srivastava <[email protected]>
-
- ## Documentation/config/advice.adoc ##
-@@ Documentation/config/advice.adoc: all advice messages.
- Shown when a sparse index is expanded to a full index, which is likely
- due to an unexpected set of files existing outside of the
- sparse-checkout.
-- stashBeforeCheckout::
-- Shown when the user attempts to switch branches but has
-- local modifications that would be overwritten by the
-- operation, to suggest using linkgit:git-stash[1] to
-- save changes before switching.
- statusAheadBehind::
- Shown when linkgit:git-status[1] computes the ahead/behind
- counts for a local ref compared to its remote tracking ref,
-
- ## advice.c ##
-@@ advice.c: static struct {
- [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
- [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
- [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
-- [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
- [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
- [ADVICE_STATUS_HINTS] = { "statusHints" },
- [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
-@@ advice.c: void advise_on_moving_dirty_path(struct string_list *pathspec_list)
- "* Use \"git add --sparse <paths>\" to update the index\n"
- "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
- }
--
--void advise_on_checkout_dirty_files(struct string_list *file_list) --{
-- struct string_list_item *item;
--
-- if (!file_list->nr)
-- return;
--
-- fprintf(stderr, _("The following files have local modifications that would\n"
-- "be overwritten by switching branches:\n"));
-- for_each_string_list_item(item, file_list)
-- fprintf(stderr, "\t%s\n", item->string);
--
-- advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
-- _("To carry your local changes over to the new branch, use:\n"
-- "\n"
-- "\tgit checkout -m <branch>\n"
-- ));
--}
-
- ## advice.h ##
-@@ advice.h: enum advice_type {
- ADVICE_SET_UPSTREAM_FAILURE,
- ADVICE_SKIPPED_CHERRY_PICKS,
- ADVICE_SPARSE_INDEX_EXPANDED,
-- ADVICE_STASH_BEFORE_CHECKOUT,
- ADVICE_STATUS_AHEAD_BEHIND_WARNING,
- ADVICE_STATUS_HINTS,
- ADVICE_STATUS_U_OPTION,
-@@ advice.h: void NORETURN die_ff_impossible(void);
- void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
- void detach_advice(const char *new_name);
- void advise_on_moving_dirty_path(struct string_list *pathspec_list); --void advise_on_checkout_dirty_files(struct string_list *file_list); -
- #endif /* ADVICE_H */
+ Signed-off-by: Arsh Srivastava [email protected]
## t/t6439-merge-co-error-msgs.sh ##
@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
t/t6439-merge-co-error-msgs.sh | 6 ++++++ t/t7406-submodule-update.sh | 3 +++ unpack-trees.c | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)
t/t6439-merge-co-error-msgs.sh +6 -0
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please commit your changes or stash them before you switch branches. +Try using 'git checkout -m <branch>' for a quick fix. +Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. +Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. Aborting EOF
t/t7406-submodule-update.sh +3 -0
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' ' > error: Your local changes to the following files would be overwritten by checkout: > file > Please commit your changes or stash them before you switch branches. + > Try using '\''git checkout -m <branch>'\'' for a quick fix. + > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. + > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. > Aborting > fatal: Unable to checkout OID in submodule path '\''submodule'\'' EOF
unpack-trees.c +7 -2
@@ -128,8 +128,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,if (!strcmp (cmd,"checkout" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ?_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches." ) - :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" ); +"Please commit your changes or stash them before you switch branches.\n" +"Try using 'git checkout -m <branch>' for a quick fix.\n" +"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n" +"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone." + ) + :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );else if (!strcmp (cmd,"merge" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Signature · 1 line
gitgitgadget
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Quoted 9 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
This comment is an extention to the already existing stash comment. Added updated comment over the already existing function "
setup_unpack_trees_porcelain" with "git checkout -m" and its repercussions
I have also mentioned the repercussions of using "-m".Signed-off-by Arsh Srivastava [email protected]
The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
Consider a more standard phrasing:
unpack-trees: suggest 'git checkout -m' when checkout fails
When a branch switch fails due to local changes, we suggest stashing or committing. However, 'git checkout -m' is a valid alternative for users who wish to carry their changes over via a merge.
Update the advice message to suggest this option, while including a warning about the potential for data loss if a hard reset is performed after a conflicted merge.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
The added message is quite long:
Quoted 5 lines
Try using 'git checkout -m <branch>' for a quick fix. Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
When advice requires a multi-line warning about potential data loss, it's often a sign that the operation being suggested isn't suitable for general advice. The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats. After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
The primary concern is that 'git checkout -m' is a high-stakes operation compared to 'git stash'.
- When a user uses 'git stash', their changes are recorded in a stash entry. If 'git stash pop' later results in conflicts they cannot resolve, the user can always 'git reset --hard' to get back to a clean state, knowing their original changes are still safe in the stash entry, which they can re-attempt to use later.
- In contrast, 'git checkout -m' performs the merge directly in the working tree. If conflicts arise, the original local changes are immediately replaced by conflict markers. Unlike stash, there is no "undo" record. If the user realizes they are in over their head, they cannot simply "abort" to get their original changes back. They have only one chance to resolve it correctly, and they have to do so right there.
Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite. However, for the health of the project's usability, it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
Thanks.
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Junio C Hamano <[email protected]> writes :
Quoted 11 lines
The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
Also showed an example for the same.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
Pointed out the difference between "stash" and "checkout -m".
When advice requires a multi-line warning about potential data loss.
The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred. For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
Thank you so much for the valuable feedback.
I will redefine my advice and will make it more precise and will change it to git stash which is truly more beneficial for the new users.
Also will update my commit so that it is properly structured with format first "why" then "what".
I will create a v7 with all these changes.
I am really obliged.
Thanks again for the guidance.
Quoted 83 lines · Junio C Hamano
Quoted 9 lines · Arsh Srivastava via GitGitGadget
From: Arsh Srivastava <[email protected]>
This comment is an extention to the already existing stash comment. Added updated comment over the already existing function "
setup_unpack_trees_porcelain" with "git checkout -m" and its repercussions
I have also mentioned the repercussions of using "-m".Signed-off-by Arsh Srivastava [email protected]The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
Consider a more standard phrasing:
unpack-trees: suggest 'git checkout -m' when checkout fails
When a branch switch fails due to local changes, we suggest stashing or committing. However, 'git checkout -m' is a valid alternative for users who wish to carry their changes over via a merge.
Update the advice message to suggest this option, while including a warning about the potential for data loss if a hard reset is performed after a conflicted merge.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
The added message is quite long:
Quoted 5 lines
Try using 'git checkout -m <branch>' for a quick fix. Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.When advice requires a multi-line warning about potential data loss, it's often a sign that the operation being suggested isn't suitable for general advice. The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats. After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
The primary concern is that 'git checkout -m' is a high-stakes operation compared to 'git stash'.
- When a user uses 'git stash', their changes are recorded in a stash entry. If 'git stash pop' later results in conflicts they cannot resolve, the user can always 'git reset --hard' to get back to a clean state, knowing their original changes are still safe in the stash entry, which they can re-attempt to use later.
- In contrast, 'git checkout -m' performs the merge directly in the working tree. If conflicts arise, the original local changes are immediately replaced by conflict markers. Unlike stash, there is no "undo" record. If the user realizes they are in over their head, they cannot simply "abort" to get their original changes back. They have only one chance to resolve it correctly, and they have to do so right there.
Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite. However, for the health of the project's usability, it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
Thanks.
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Quoted 12 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 11 lines
The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
Also showed an example for the same.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
Pointed out the difference between "stash" and "checkout -m".
When advice requires a multi-line warning about potential data loss.
The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred. For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to. Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
What is more usual is to quote the message you are responding to, trim the parts you are not going to comment on and not necessary for bystanders to read in order to understand your response, and then sprinkle your comments in between the parts of the quoted message, instead of saying only your thing before the message you are responding to without trimming (which is highly frowned upon, and people often tell you not to "top-post").
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Junio C Hamano <[email protected]> write:
Quoted 3 lines
I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to. Is this LLM-generated summary that was copied-and-pasted without much human brain effort? What is more usual is to quote the message you are responding to.
Actually as suspicious as it looks the mail was written by me only and I thought that each line was as important as other and
I wanted to reply to each point you mentioned
Sorry for shortening your response
next time I will make sure that I will make quotations direct.
Quoted 28 lines · Junio C Hamano
Quoted 12 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 11 lines
The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
Also showed an example for the same.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
Pointed out the difference between "stash" and "checkout -m".
When advice requires a multi-line warning about potential data loss.
The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred. For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to. Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
What is more usual is to quote the message you are responding to, trim the parts you are not going to comment on and not necessary for bystanders to read in order to understand your response, and then sprinkle your comments in between the parts of the quoted message, instead of saying only your thing before the message you are responding to without trimming (which is highly frowned upon, and people often tell you not to "top-post").
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Quoted 10 lines · Arsh Srivastava
Junio C Hamano <[email protected]> write:
Quoted 3 lines
I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to. Is this LLM-generated summary that was copied-and-pasted without much human brain effort? What is more usual is to quote the message you are responding to.
Actually as suspicious as it looks the mail was written by me only and I thought that each line was as important as other and
I wanted to reply to each point you mentioned
Sorry for shortening your response
next time I will make sure that I will make quotations direct.
That wasn't what I meant, and you are still top-posting X-<.
Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
Junio C Hamano <[email protected]> write:
Quoted 1 line
That wasn't what I meant, and you are still top-posting X-<.
Oh.. I understand now I mistakenly again used top-posting mail (-< which is frustrating
I will use the recommended method only from now on. : )
Quoted 15 lines · Junio C Hamano
Quoted 10 lines · Arsh Srivastava
Junio C Hamano <[email protected]> write:
Quoted 3 lines
I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to. Is this LLM-generated summary that was copied-and-pasted without much human brain effort? What is more usual is to quote the message you are responding to.
Actually as suspicious as it looks the mail was written by me only and I thought that each line was as important as other and
I wanted to reply to each point you mentioned
Sorry for shortening your response
next time I will make sure that I will make quotations direct.That wasn't what I meant, and you are still top-posting X-<.
PATCH v7 1/1 unpack-trees: suggest using 'git stash' when checkout fails
In reply to Arsh Srivastava via GitGitGadgetFrom: Arsh Srivastava <[email protected]>
When a branch switch fails due to local changes and
new users who are not familiar with the error message often get confused about how to move ahead and resolve the issue as the previous error message only suggests to commit or stash the changes but doesn't explain how to do that or what the next steps are.
This patch enhances the error message with more specific instructions in a concise manner to help users understand how to resolve the issue and move their local changes safely to the other branch using stash.
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and > checkout tests. t/t7406-submodule-update.sh: update expected output > for submodule checkout tests.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v7
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v6:
1: e0ba5fad82 ! 1: 72cb550621 unpack-trees: suggesting 'git checkout -m' with its repercussions
@@ Metadata
Author: Arsh Srivastava <[email protected]>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m' with its repercussions
+ unpack-trees: suggest using 'git stash' when checkout fails
- This comment is an extention to the already existing stash comment.
- Added updated comment over the already existing function
- "setup_unpack_trees_porcelain" with "git checkout -m"
- and its repercussions
- I have also mentioned the repercussions of using "-m".
+ When a branch switch fails due to local changes and
+ new users who are not familiar with the error message often
+ get confused about how to move ahead and resolve the issue as
+ the previous error message only suggests to commit or stash the changes
+ but doesn't explain how to do that or what the next steps are.
- Signed-off-by: Arsh Srivastava [email protected]
+ This patch enhances the error message with more specific
+ instructions in a concise manner to help users understand
+ how to resolve the issue and move their local changes
+ safely to the other branch using stash.
+
+ Signed-off-by: Arsh Srivastava <[email protected]>
## t/t6439-merge-co-error-msgs.sh ##
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou +@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. -+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. +-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou +@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. -+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone. +-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
## t/t7406-submodule-update.sh ##
@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
> file
- > Please commit your changes or stash them before you switch branches.
-+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
-+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+- > Please commit your changes or stash them before you switch branches.
++ > To move you local changes safely to the other branch,
++ > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
-+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
-+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
-+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
++ "To move you local changes safely to the other branch,\n"
++ "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.");
t/t6439-merge-co-error-msgs.sh | 6 ++++-- t/t7406-submodule-update.sh | 3 ++- unpack-trees.c | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-)
t/t6439-merge-co-error-msgs.sh +4 -2
@@ -76,7 +76,8 @@ cat >expect <<\EOF error: Your local changes to the following files would be overwritten by checkout: rep/one rep/two -Please commit your changes or stash them before you switch branches. +To move you local changes safely to the other branch, +Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge. Aborting EOF
@@ -98,7 +99,8 @@ cat >expect <<\EOF error: Your local changes to the following files would be overwritten by checkout: rep/one rep/two -Please commit your changes or stash them before you switch branches. +To move you local changes safely to the other branch, +Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge. Aborting EOF
t/t7406-submodule-update.sh +2 -1
@@ -211,7 +211,8 @@ test_expect_success 'submodule update should fail due to local changes' ' sed "s/^> //" >expect <<-\EOF && > error: Your local changes to the following files would be overwritten by checkout: > file - > Please commit your changes or stash them before you switch branches. + > To move you local changes safely to the other branch, + > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge. > Aborting > fatal: Unable to checkout OID in submodule path '\''submodule'\'' EOF
unpack-trees.c +5 -2
@@ -128,8 +128,11 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,if (!strcmp (cmd,"checkout" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ?_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches." ) - :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" ); +"To move you local changes safely to the other branch,\n" +"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." + ) + :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );else if (!strcmp (cmd,"merge" )) msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Signature · 1 line
gitgitgadget
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
Quoted 5 lines · Arsh Srivastava via GitGitGadget
When a branch switch fails due to local changes and
new users who are not familiar with the error message often get confused about how to move ahead and resolve the issue as the previous error message only suggests to commit or stash the changes but doesn't explain how to do that or what the next steps are.
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who are unfamiliar with the error message often get confused about how to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is. The _current_ message stops at hinting the commands to be used without giving wordy instructions that are best left to manuals. You may view it as a weakness (which may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.
Quoted 4 lines
This patch enhances the error message with more specific instructions in a concise manner to help users understand how to resolve the issue and move their local changes safely to the other branch using stash.
As Documentation/SubmittingPatches says, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".
By the way, the updated message seems much less concise than the original.
unpack-trees.c void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, · line 135
Quoted 9 lines
unpack-trees.c +5
-2msg =advice_enabled (ADVICE_COMMIT_BEFORE_MERGE ) ?_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" -"Please commit your changes or stash them before you switch branches." ) - :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" ); +"To move you local changes safely to the other branch,\n" +"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." + ) + :_ ("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
The original was this:
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.")
: _("Your local changes to the following files would be overwritten by checkout:\n%%s");Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");
without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." )
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.");
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thanks.
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
Junio C Hamano <[email protected]> writes :
Quoted 3 lines
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence. Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible. With less punctuations and shorter sentences which will in turn make it more concise.
Quoted 3 lines
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is.
Understood I will in future not use previous because it is the _current_ code.
Quoted 4 lines
You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.
I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 3 lines
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".
Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.
Quoted 3 lines
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
That makes total sense.
Quoted 3 lines
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Thank you so much for your guidance the advice should not trigger to those who have opted not to see.
My code might have misjudged this paradigm.
Quoted 1 line
Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't. I will remember to be more cautious next time.
Quoted 3 lines
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision for exploring.
Quoted 3 lines
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
I don't want to sound like a programmed robot but I absolutely agree with the recommendations.
Quoted 2 lines
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below, As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged? Because I have already shown I can navigate git project which was the goal of micro projects in the first place.
Quoted 101 lines · Junio C Hamano
Quoted 5 lines · Arsh Srivastava via GitGitGadget
When a branch switch fails due to local changes and
new users who are not familiar with the error message often get confused about how to move ahead and resolve the issue as the previous error message only suggests to commit or stash the changes but doesn't explain how to do that or what the next steps are.The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who are unfamiliar with the error message often get confused about how to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is. The _current_ message stops at hinting the commands to be used without giving wordy instructions that are best left to manuals. You may view it as a weakness (which may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.
Quoted 4 lines
This patch enhances the error message with more specific instructions in a concise manner to help users understand how to resolve the issue and move their local changes safely to the other branch using stash.
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".By the way, the updated message seems much less concise than the original.
unpack-trees.c void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, · line 135
Quoted 9 lines
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"unpack-trees.c +5
-2- "Please commit your changes or stash them before you switch branches.") - : _("Your local changes to the following files would be overwritten by checkout:\n%%s"); + "To move you local changes safely to the other branch,\n" + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." + ) + : _("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
The original was this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.")
:_("Your local changes to the following files would be overwritten by checkout:\n%%s");Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." )
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.");to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thanks.
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
Quoted 70 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 3 lines
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence. Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible. With less punctuations and shorter sentences which will in turn make it more concise.
Quoted 3 lines
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is.
Understood I will in future not use previous because it is the _current_ code.
Quoted 4 lines
You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 3 lines
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.Quoted 3 lines
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
That makes total sense.
Quoted 3 lines
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Thank you so much for your guidance the advice should not trigger to those who have opted not to see.
My code might have misjudged this paradigm.Quoted 1 line
Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't. I will remember to be more cautious next time.
Quoted 3 lines
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision for exploring.
Quoted 3 lines
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
I don't want to sound like a programmed robot but I absolutely agree with the recommendations.
Quoted 2 lines
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Quoted 10 lines
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below, As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged? Because I have already shown I can navigate git project which was the goal of micro projects in the first place.
From the micro-project information [1] for GSoC we have:
The coding part of the microproject should be very small (say, 10-30 minutes). We don’t require that your patch be accepted into the “master” branch by the time of your formal application; we mostly want to see that you have a basic level of competence and especially the ability to interact with the other Git developers.
As such and seeing Junio's previous response, I would say that no further work is required here.
[1]: https://git.github.io/General-Microproject-Information/
[snip]
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
In reply to Arsh SrivastavaQuoted 3 lines · Arsh Srivastava
I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Actually the above text should be :-
I understand, git wants people to explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 183 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 3 lines
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence. Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible. With less punctuations and shorter sentences which will in turn make it more concise.
Quoted 3 lines
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is.
Understood I will in future not use previous because it is the _current_ code.
Quoted 4 lines
You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 3 lines
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.Quoted 3 lines
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
That makes total sense.
Quoted 3 lines
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Thank you so much for your guidance the advice should not trigger to those who have opted not to see.
My code might have misjudged this paradigm.Quoted 1 line
Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't. I will remember to be more cautious next time.
Quoted 3 lines
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision for exploring.
Quoted 3 lines
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
I don't want to sound like a programmed robot but I absolutely agree with the recommendations.
Quoted 2 lines
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below, As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged? Because I have already shown I can navigate git project which was the goal of micro projects in the first place.Quoted 101 lines · Junio C Hamano
Quoted 5 lines · Arsh Srivastava via GitGitGadget
When a branch switch fails due to local changes and
new users who are not familiar with the error message often get confused about how to move ahead and resolve the issue as the previous error message only suggests to commit or stash the changes but doesn't explain how to do that or what the next steps are.The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who are unfamiliar with the error message often get confused about how to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is. The _current_ message stops at hinting the commands to be used without giving wordy instructions that are best left to manuals. You may view it as a weakness (which may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.
Quoted 4 lines
This patch enhances the error message with more specific instructions in a concise manner to help users understand how to resolve the issue and move their local changes safely to the other branch using stash.
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".By the way, the updated message seems much less concise than the original.
unpack-trees.c void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, · line 135
Quoted 9 lines
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"unpack-trees.c +5
-2- "Please commit your changes or stash them before you switch branches.") - : _("Your local changes to the following files would be overwritten by checkout:\n%%s"); + "To move you local changes safely to the other branch,\n" + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." + ) + : _("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
The original was this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.")
:_("Your local changes to the following files would be overwritten by checkout:\n%%s");Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." )
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.");to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thanks.
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
In reply to Karthik NayakKarthik Nayak <[email protected]> writes :
Quoted 2 lines
We don’t require that your patch be accepted into the “master” branch by the time of your formal application
Understandable
Quoted 3 lines
we mostly want to see that you have a basic level of competence and especially the
ability to interact with the other Git developers.
Truly this is something that is very important in any organization.
Quoted 2 lines
As such and seeing Junio's previous response, I would say that no further work is required here.
Thank you so much for your valuable guidance, I will now draft a formal proposal for GSoC and I look forward to working with you in the future too. :)
Quoted 98 lines · Karthik Nayak
Quoted 70 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 3 lines
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence. Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible. With less punctuations and shorter sentences which will in turn make it more concise.
Quoted 3 lines
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is.
Understood I will in future not use previous because it is the _current_ code.
Quoted 4 lines
You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 3 lines
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.Quoted 3 lines
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
That makes total sense.
Quoted 3 lines
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Thank you so much for your guidance the advice should not trigger to those who have opted not to see.
My code might have misjudged this paradigm.Quoted 1 line
Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't. I will remember to be more cautious next time.
Quoted 3 lines
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision for exploring.
Quoted 3 lines
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
I don't want to sound like a programmed robot but I absolutely agree with the recommendations.
Quoted 2 lines
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Quoted 10 lines
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below, As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged? Because I have already shown I can navigate git project which was the goal of micro projects in the first place.From the micro-project information [1] for GSoC we have:
The coding part of the microproject should be very small (say, 10-30 minutes). We don’t require that your patch be accepted into the “master” branch by the time of your formal application; we mostly want to see that you have a basic level of competence and especially the ability to interact with the other Git developers.
As such and seeing Junio's previous response, I would say that no further work is required here.
[1]: https://git.github.io/General-Microproject-Information/
[snip]
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
In reply to Arsh SrivastavaQuoted 1 line · Arsh Srivastava
I understand, git wants people to not explore the available
This was a typo the real text is :
I understand, git wants people to explore the available
Quoted 183 lines · Arsh Srivastava
Junio C Hamano <[email protected]> writes :
Quoted 3 lines
The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence. Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible. With less punctuations and shorter sentences which will in turn make it more concise.
Quoted 3 lines
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is.
Understood I will in future not use previous because it is the _current_ code.
Quoted 4 lines
You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.I understand, git wants people to not explore the available change options and help them make logical decisions rather than pushing them with some unneeded commands.
Quoted 3 lines
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.Quoted 3 lines
These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
That makes total sense.
Quoted 3 lines
to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Thank you so much for your guidance the advice should not trigger to those who have opted not to see.
My code might have misjudged this paradigm.Quoted 1 line
Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't. I will remember to be more cautious next time.
Quoted 3 lines
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision for exploring.
Quoted 3 lines
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
I don't want to sound like a programmed robot but I absolutely agree with the recommendations.
Quoted 2 lines
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below, As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged? Because I have already shown I can navigate git project which was the goal of micro projects in the first place.Quoted 101 lines · Junio C Hamano
Quoted 5 lines · Arsh Srivastava via GitGitGadget
When a branch switch fails due to local changes and
new users who are not familiar with the error message often get confused about how to move ahead and resolve the issue as the previous error message only suggests to commit or stash the changes but doesn't explain how to do that or what the next steps are.The first paragraph is a bit of a run-on and has a misplaced "and"; I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who are unfamiliar with the error message often get confused about how to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk about the current code in the present tense, to highlight what the problem in the current code is. The _current_ message stops at hinting the commands to be used without giving wordy instructions that are best left to manuals. You may view it as a weakness (which may motivate this patch to be written). But I personally am not so sure that adding words to the existing message would necessarily make it more clear.
Quoted 4 lines
This patch enhances the error message with more specific instructions in a concise manner to help users understand how to resolve the issue and move their local changes safely to the other branch using stash.
As
Documentation/SubmittingPatchessays, let's instruct the code to "be like so" in imperative mood. E.g., "Enhance the error message..." instead of "This patch enhances...".By the way, the updated message seems much less concise than the original.
unpack-trees.c void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, · line 135
Quoted 9 lines
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"unpack-trees.c +5
-2- "Please commit your changes or stash them before you switch branches.") - : _("Your local changes to the following files would be overwritten by checkout:\n%%s"); + "To move you local changes safely to the other branch,\n" + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." + ) + : _("Your local changes to the following files would be overwritten by checkout:\n%%s" +"Please commit your changes or stash them before you switch branches." );These were already overly long, but the updated one is way too long to be read on end-user's terminal. The source lines are overly long, too.
The original was this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.")
:_("Your local changes to the following files would be overwritten by checkout:\n%%s");Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg =
advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge." )
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.");to those users who decline the advice, we now show "Please commit...". That is not what !advice_enabled() should trigger, is it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the work in progress on the original branch before switching, yet the new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a "checkout" might be slightly confusing, even if 'stash pop' involves a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike the right balance between being clear and being concise.
Thanks.
Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
In reply to Karthik NayakQuoted 8 lines · Karthik Nayak
From the micro-project information [1] for GSoC we have:
The coding part of the microproject should be very small (say, 10-30 minutes). We don’t require that your patch be accepted into the “master” branch by the time of your formal application; we mostly want to see that you have a basic level of competence and especially the ability to interact with the other Git developers.
Quoted 4 lines
As such and seeing Junio's previous response, I would say that no further work is required here.
[1]: https://git.github.io/General-Microproject-Information/
Thanks ;-).
Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
In reply to Karthik NayakQuoted 9 lines · Karthik Nayak
Quoted 7 lines
Quoted 3 lines
I will rework the patch in that direction and send a v4.
Signed-off-by Arsh Srivastava <[email protected]>Just a comment by a bystander, but it confuses me quite a lot to see in-body "Subject:" and "Sign-off" in a message that is *not* a patch at all. What are you signing off with this signature?
Tangentially, I know that b4 adds a "Sign-off" to the cover message.
This is a feature, because some subsystems use the cover message as the source for the merge commit, so the cover message *is* a commit despite not being a patch. :)
Regards,
Signature · 1 line
KR