Skip to content

Commit 1cc22f4

Browse files
committed
unpack-trees: suggesting 'git checkout -m <branch>' 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>" and its repercussions I have also mentioned the repercussions of using "-m". Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
1 parent e88c851 commit 1cc22f4

File tree

6 files changed

+16
-29
lines changed

6 files changed

+16
-29
lines changed

Documentation/config/advice.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ all advice messages.
126126
Shown when a sparse index is expanded to a full index, which is likely
127127
due to an unexpected set of files existing outside of the
128128
sparse-checkout.
129-
stashBeforeCheckout::
130-
Shown when the user attempts to switch branches but has
131-
local modifications that would be overwritten by the
132-
operation, to suggest using linkgit:git-stash[1] to
133-
save changes before switching.
134129
statusAheadBehind::
135130
Shown when linkgit:git-status[1] computes the ahead/behind
136131
counts for a local ref compared to its remote tracking ref,

advice.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static struct {
8181
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
8282
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
8383
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
84-
[ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
8584
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
8685
[ADVICE_STATUS_HINTS] = { "statusHints" },
8786
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
313312
"* Use \"git add --sparse <paths>\" to update the index\n"
314313
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
315314
}
316-
317-
void advise_on_checkout_dirty_files(struct string_list *file_list)
318-
{
319-
struct string_list_item *item;
320-
321-
if (!file_list->nr)
322-
return;
323-
324-
fprintf(stderr, _("The following files have local modifications that would\n"
325-
"be overwritten by switching branches:\n"));
326-
for_each_string_list_item(item, file_list)
327-
fprintf(stderr, "\t%s\n", item->string);
328-
329-
advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
330-
_("To carry your local changes over to the new branch, use:\n"
331-
"\n"
332-
"\tgit checkout -m <branch>\n"
333-
));
334-
}

advice.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ enum advice_type {
4848
ADVICE_SET_UPSTREAM_FAILURE,
4949
ADVICE_SKIPPED_CHERRY_PICKS,
5050
ADVICE_SPARSE_INDEX_EXPANDED,
51-
ADVICE_STASH_BEFORE_CHECKOUT,
5251
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
5352
ADVICE_STATUS_HINTS,
5453
ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);
8483
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
8584
void detach_advice(const char *new_name);
8685
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
87-
void advise_on_checkout_dirty_files(struct string_list *file_list);
8886

8987
#endif /* ADVICE_H */

t/t6439-merge-co-error-msgs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou
7777
rep/one
7878
rep/two
7979
Please commit your changes or stash them before you switch branches.
80+
Try using 'git checkout -m <branch>' for a quick fix.
81+
Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
82+
Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
8083
Aborting
8184
EOF
8285

@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou
99102
rep/one
100103
rep/two
101104
Please commit your changes or stash them before you switch branches.
105+
Try using 'git checkout -m <branch>' for a quick fix.
106+
Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
107+
Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
102108
Aborting
103109
EOF
104110

t/t7406-submodule-update.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' '
212212
> error: Your local changes to the following files would be overwritten by checkout:
213213
> file
214214
> Please commit your changes or stash them before you switch branches.
215+
> Try using '\''git checkout -m <branch>'\'' for a quick fix.
216+
> Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
217+
> Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
215218
> Aborting
216219
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
217220
EOF

unpack-trees.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
128128
if (!strcmp(cmd, "checkout"))
129129
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
130130
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
131-
"Please commit your changes or stash them before you switch branches.")
132-
: _("Your local changes to the following files would be overwritten by checkout:\n%%s");
131+
"Please commit your changes or stash them before you switch branches.\n"
132+
"Try using 'git checkout -m <branch>' for a quick fix.\n"
133+
"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
134+
"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
135+
)
136+
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
137+
"Please commit your changes or stash them before you switch branches.");
133138
else if (!strcmp(cmd, "merge"))
134139
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
135140
? _("Your local changes to the following files would be overwritten by merge:\n%%s"

0 commit comments

Comments
 (0)