Skip to content

Commit d7394c3

Browse files
author
Carson Howard
committed
examples: ls-files: print entry path only when entry is found
1 parent 29ca3f3 commit d7394c3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

examples/ls-files.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int print_paths(ls_options *opts, git_index *index)
8383
{
8484
size_t i;
8585
const git_index_entry *entry;
86-
86+
8787
/* if there are not files explicitly listed by the user print all entries in the index */
8888
if (opts->file_count == 0) {
8989
size_t entry_count = git_index_entrycount(index);
@@ -99,14 +99,13 @@ static int print_paths(ls_options *opts, git_index *index)
9999
for (i = 0; i < opts->file_count; ++i) {
100100
const char *path = opts->files[i];
101101

102-
entry = git_index_get_bypath(index, path, GIT_INDEX_STAGE_NORMAL);
103-
if (!entry && opts->error_unmatch) {
102+
if ((entry = git_index_get_bypath(index, path, GIT_INDEX_STAGE_NORMAL)) != NULL) {
103+
printf("%s\n", path);
104+
} else if (opts->error_unmatch) {
104105
fprintf(stderr, "error: pathspec '%s' did not match any file(s) known to git.\n", path);
105106
fprintf(stderr, "Did you forget to 'git add'?\n");
106107
return -1;
107108
}
108-
109-
printf("%s\n", path);
110109
}
111110

112111
return 0;

0 commit comments

Comments
 (0)