Skip to content

Commit 6c78fd0

Browse files
authored
Merge pull request libgit2#5915 from novalis/executable
Consider files executable only if the user can execute them
2 parents 992f65f + b0fd4cf commit 6c78fd0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/futils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ extern int git_futils_truncate(const char *path, int mode);
257257
*/
258258
extern int git_futils_filesize(uint64_t *out, git_file fd);
259259

260-
#define GIT_PERMS_IS_EXEC(MODE) (((MODE) & 0111) != 0)
260+
#define GIT_PERMS_IS_EXEC(MODE) (((MODE) & 0100) != 0)
261261
#define GIT_PERMS_CANONICAL(MODE) (GIT_PERMS_IS_EXEC(MODE) ? 0755 : 0644)
262262
#define GIT_PERMS_FOR_WRITE(MODE) (GIT_PERMS_IS_EXEC(MODE) ? 0777 : 0666)
263263

tests/status/worktree.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,45 @@ void test_status_worktree__filemode_changes(void)
605605
cl_assert_equal_i(0, counts.wrong_sorted_path);
606606
}
607607

608+
void test_status_worktree__filemode_non755(void)
609+
{
610+
git_repository *repo = cl_git_sandbox_init("filemodes");
611+
status_entry_counts counts;
612+
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
613+
git_buf executable_path = GIT_BUF_INIT;
614+
git_buf nonexecutable_path = GIT_BUF_INIT;
615+
616+
if (!cl_is_chmod_supported())
617+
return;
618+
619+
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
620+
GIT_STATUS_OPT_INCLUDE_IGNORED |
621+
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
622+
623+
git_buf_joinpath(&executable_path, git_repository_workdir(repo), "exec_on");
624+
cl_must_pass(p_chmod(git_buf_cstr(&executable_path), 0744));
625+
git_buf_dispose(&executable_path);
626+
627+
git_buf_joinpath(&nonexecutable_path, git_repository_workdir(repo), "exec_off");
628+
629+
cl_must_pass(p_chmod(git_buf_cstr(&nonexecutable_path), 0655));
630+
git_buf_dispose(&nonexecutable_path);
631+
632+
memset(&counts, 0, sizeof(counts));
633+
counts.expected_entry_count = filemode_count;
634+
counts.expected_paths = filemode_paths;
635+
counts.expected_statuses = filemode_statuses;
636+
637+
cl_git_pass(
638+
git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)
639+
);
640+
641+
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
642+
cl_assert_equal_i(0, counts.wrong_status_flags_count);
643+
cl_assert_equal_i(0, counts.wrong_sorted_path);
644+
}
645+
646+
608647
static int cb_status__interrupt(const char *p, unsigned int s, void *payload)
609648
{
610649
volatile int *count = (int *)payload;

0 commit comments

Comments
 (0)