This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c | |
| index b623239..cf0a56b 100644 | |
| --- a/builtin/rev-parse.c | |
| +++ b/builtin/rev-parse.c | |
| @@ -507,6 +507,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | |
| int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0; | |
| int has_dashdash = 0; | |
| int output_prefix = 0; | |
| + int is_n = 0; | |
| + int is_result = 0; | |
| + int return_code = 0; | |
| unsigned char sha1[20]; | |
| unsigned int flags = 0; | |
| const char *name = NULL; | |
| @@ -777,18 +780,36 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | |
| continue; | |
| } | |
| if (!strcmp(arg, "--is-inside-git-dir")) { | |
| - printf("%s\n", is_inside_git_dir() ? "true" | |
| - : "false"); | |
| + is_result = is_inside_git_dir(); | |
| + if (quiet == 1) { | |
| + return_code |= is_result * (1 << is_n); | |
| + is_n += 1; | |
| + } else { | |
| + printf("%s\n", is_result ? "true" | |
| + : "false"); | |
| + } | |
| continue; | |
| } | |
| if (!strcmp(arg, "--is-inside-work-tree")) { | |
| - printf("%s\n", is_inside_work_tree() ? "true" | |
| - : "false"); | |
| + is_result = is_inside_work_tree(); | |
| + if (quiet == 1) { | |
| + return_code |= is_result * (1 << is_n); | |
| + is_n += 1; | |
| + } else { | |
| + printf("%s\n", is_result ? "true" | |
| + : "false"); | |
| + } | |
| continue; | |
| } | |
| if (!strcmp(arg, "--is-bare-repository")) { | |
| - printf("%s\n", is_bare_repository() ? "true" | |
| - : "false"); | |
| + is_result = is_bare_repository(); | |
| + if (quiet == 1) { | |
| + return_code |= is_result * (1 << is_n); | |
| + is_n += 1; | |
| + } else { | |
| + printf("%s\n", is_result ? "true" | |
| + : "false"); | |
| + } | |
| continue; | |
| } | |
| if (!strcmp(arg, "--shared-index-path")) { | |
| @@ -848,6 +869,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | |
| continue; | |
| verify_filename(prefix, arg, 1); | |
| } | |
| + if (quiet && !verify) { | |
| + return return_code; | |
| + } | |
| if (verify) { | |
| if (revs_count == 1) { | |
| show_rev(type, sha1, name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment