commit 3642c4c6513e3536dc77e8f2b7a2402d1aa916a7 from: Stefan Sperling date: Tue Jul 09 08:55:36 2019 UTC tog: stop interpreting unknown commands as paths commit - 57b33b641c4fe9ecd381906cdc6fcf1187db2b1e commit + 3642c4c6513e3536dc77e8f2b7a2402d1aa916a7 blob - e53014756f2f4a7818f13198482b7cb2fccad37c blob + 78b5d6575911a8e95cb646a1cc1e74263cb21eb4 --- tog/tog.c +++ tog/tog.c @@ -4538,46 +4538,23 @@ main(int argc, char *argv[]) if (strncmp(tog_commands[i].name, argv[0], strlen(argv[0])) == 0) { cmd = &tog_commands[i]; - if (hflag) - tog_commands[i].cmd_usage(); break; } } + if (cmd == NULL) { - /* Did the user specify a repository? */ - char *repo_path = realpath(argv[0], NULL); - if (repo_path) { - struct got_repository *repo; - error = got_repo_open(&repo, repo_path); - if (error == NULL) - got_repo_close(repo); - } else - error = got_error_from_errno2("realpath", - argv[0]); - if (error) { - if (hflag) { - fprintf(stderr, "%s: '%s' is not a " - "known command\n", getprogname(), - argv[0]); - usage(); - } - fprintf(stderr, "%s: '%s' is neither a known " - "command nor a path to a repository\n", - getprogname(), argv[0]); - free(repo_path); - return 1; - } - cmd = &tog_commands[0]; - cmd_argv = make_argv(cmd->name, repo_path); - argc = 2; - free(repo_path); + fprintf(stderr, "%s: unkown command '%s'\n", + getprogname(), argv[0]); + usage(); + return 1; } } - error = cmd->cmd_main(argc, cmd_argv ? cmd_argv : argv); - if (error) - goto done; -done: + if (hflag) + cmd->cmd_usage(); + else + error = cmd->cmd_main(argc, cmd_argv ? cmd_argv : argv); + endwin(); free(cmd_argv); if (error)