Skip to content

Commit eb23dcd

Browse files
committed
git: catch an attempt to run "git-foo"
If we were to propose removing "git-foo" binaries from the filesystem for built-in commands, we should first see if there are users who will be affected by such a move. When cmd_main() detects we were called not as "git", but as "git-foo", give an error message to ask the user to let us know and stop our removal plan, unless we are running a selected few programs that MUST be callable in the dashed form (e.g. "git-upload-pack"). Those who are always using "git foo" form will not be affected, but those who trusted the promise we made to them 12 years ago that by prepending the output of $(git --exec-path) to the list of directories on their $PATH, they can safely keep writing "git-cat-file" will be negatively affected as all their scripts assuming the promise will be kept are now broken. Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0e190c commit eb23dcd

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

command-list.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
# mainporcelain commands are completable so you don't need this
4040
# attribute.
4141
#
42+
# "onpath" attribute is used to mark that the command MUST appear
43+
# on $PATH (typically in /usr/bin) due to protocol requirement.
44+
#
4245
# As part of the Git man page list, the man(5/7) guides are also
4346
# specified here, which can only have "guide" attribute and nothing
4447
# else.
@@ -144,7 +147,7 @@ git-quiltimport foreignscminterface
144147
git-range-diff mainporcelain
145148
git-read-tree plumbingmanipulators
146149
git-rebase mainporcelain history
147-
git-receive-pack synchelpers
150+
git-receive-pack synchelpers onpath
148151
git-reflog ancillarymanipulators complete
149152
git-remote ancillarymanipulators complete
150153
git-repack ancillarymanipulators complete
@@ -159,7 +162,7 @@ git-rev-parse plumbinginterrogators
159162
git-rm mainporcelain worktree
160163
git-send-email foreignscminterface complete
161164
git-send-pack synchingrepositories
162-
git-shell synchelpers
165+
git-shell synchelpers onpath
163166
git-shortlog mainporcelain
164167
git-show mainporcelain info
165168
git-show-branch ancillaryinterrogators complete
@@ -182,8 +185,8 @@ git-unpack-objects plumbingmanipulators
182185
git-update-index plumbingmanipulators
183186
git-update-ref plumbingmanipulators
184187
git-update-server-info synchingrepositories
185-
git-upload-archive synchelpers
186-
git-upload-pack synchelpers
188+
git-upload-archive synchelpers onpath
189+
git-upload-pack synchelpers onpath
187190
git-var plumbinginterrogators
188191
git-verify-commit ancillaryinterrogators
189192
git-verify-pack plumbinginterrogators

git.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ int cmd_main(int argc, const char **argv)
839839
* that one cannot handle it.
840840
*/
841841
if (skip_prefix(cmd, "git-", &cmd)) {
842+
warn_on_dashed_git(argv[0]);
843+
842844
argv[0] = cmd;
843845
handle_builtin(argc, argv);
844846
die(_("cannot handle %s as a builtin"), cmd);

help.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,3 +720,37 @@ NORETURN void help_unknown_ref(const char *ref, const char *cmd,
720720
string_list_clear(&suggested_refs, 0);
721721
exit(1);
722722
}
723+
724+
static struct cmdname_help *find_cmdname_help(const char *name)
725+
{
726+
int i;
727+
728+
for (i = 0; i < ARRAY_SIZE(command_list); i++) {
729+
if (!strcmp(command_list[i].name, name))
730+
return &command_list[i];
731+
}
732+
return NULL;
733+
}
734+
735+
void warn_on_dashed_git(const char *cmd)
736+
{
737+
struct cmdname_help *cmdname;
738+
static const char *still_in_use_var = "GIT_I_STILL_USE_DASHED_GIT";
739+
static const char *still_in_use_msg =
740+
N_("Use of '%s' in the dashed-form is nominated for removal.\n"
741+
"If you still use it, export '%s=true'\n"
742+
"and send an e-mail to <[email protected]>\n"
743+
"to let us know and stop our removal plan. Thanks.\n");
744+
745+
if (!cmd)
746+
return; /* git-help is OK */
747+
748+
cmdname = find_cmdname_help(cmd);
749+
if (cmdname && (cmdname->category & CAT_onpath))
750+
return; /* git-upload-pack and friends are OK */
751+
752+
if (!git_env_bool(still_in_use_var, 0)) {
753+
fprintf(stderr, _(still_in_use_msg), cmd, still_in_use_var);
754+
exit(1);
755+
}
756+
}

help.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void get_version_info(struct strbuf *buf, int show_build_options);
4545
*/
4646
NORETURN void help_unknown_ref(const char *ref, const char *cmd, const char *error);
4747

48+
/* When the cmd_main() sees "git-foo", check if the user intended */
49+
void warn_on_dashed_git(const char *);
50+
4851
static inline void list_config_item(struct string_list *list,
4952
const char *prefix,
5053
const char *str)

0 commit comments

Comments
 (0)