Skip to content

Instantly share code, notes, and snippets.

@Ikke

Ikke/.diff Secret

Created July 29, 2015 23:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Ikke/6d502d23b0a0eeab0486 to your computer and use it in GitHub Desktop.
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