Skip to content

Commit 658ff47

Browse files
committed
builtin/rm.c: consolidate error reporting for removing submodules
We have two (not identical) copies of error reporting when attempting to remove submodules that have their repositories embedded within them. Add a helper function so that we do not have to repeat similar error messages with subtly different wording without a good reason. Noticed by Jiang Xin. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 914dc02 commit 658ff47

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

builtin/rm.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ static void print_error_files(struct string_list *files_list,
5757
}
5858
}
5959

60+
static void error_removing_concrete_submodules(struct string_list *files, int *errs)
61+
{
62+
print_error_files(files,
63+
Q_("the following submodule (or one of its nested "
64+
"submodules)\n"
65+
"uses a .git directory:",
66+
"the following submodules (or one of its nested "
67+
"submodules)\n"
68+
"use a .git directory:", files->nr),
69+
_("\n(use 'rm -rf' if you really want to remove "
70+
"it including all of its history)"),
71+
errs);
72+
string_list_clear(files, 0);
73+
}
74+
6075
static int check_submodules_use_gitfiles(void)
6176
{
6277
int i;
@@ -85,16 +100,8 @@ static int check_submodules_use_gitfiles(void)
85100
if (!submodule_uses_gitfile(name))
86101
string_list_append(&files, name);
87102
}
88-
print_error_files(&files,
89-
Q_("the following submodule (or one of its nested "
90-
"submodules)\n uses a .git directory:",
91-
"the following submodules (or one of its nested "
92-
"submodules)\n use a .git directory:",
93-
files.nr),
94-
_("\n(use 'rm -rf' if you really want to remove "
95-
"it including all of its history)"),
96-
&errs);
97-
string_list_clear(&files, 0);
103+
104+
error_removing_concrete_submodules(&files, &errs);
98105

99106
return errs;
100107
}
@@ -236,17 +243,9 @@ static int check_local_mod(unsigned char *head, int index_only)
236243
" or -f to force removal)"),
237244
&errs);
238245
string_list_clear(&files_cached, 0);
239-
print_error_files(&files_submodule,
240-
Q_("the following submodule (or one of its nested "
241-
"submodule)\nuses a .git directory:",
242-
"the following submodules (or one of its nested "
243-
"submodule)\nuse a .git directory:",
244-
files_submodule.nr),
245-
_("\n(use 'rm -rf' if you really "
246-
"want to remove it including all "
247-
"of its history)"),
248-
&errs);
249-
string_list_clear(&files_submodule, 0);
246+
247+
error_removing_concrete_submodules(&files_submodule, &errs);
248+
250249
print_error_files(&files_local,
251250
Q_("the following file has local modifications:",
252251
"the following files have local modifications:",

0 commit comments

Comments
 (0)