mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-26 03:42:28 +00:00
Checkout: handle file modes properly.
Global file mode override now works properly with the file mode stored in the tree node.
This commit is contained in:
parent
3f584b5027
commit
8e4aae1ae5
@ -61,11 +61,13 @@ static int blob_contents_to_link(tree_walk_data *data, git_buf *fnbuf,
|
|||||||
|
|
||||||
|
|
||||||
static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
|
static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
|
||||||
const git_oid *id, tree_walk_data *data)
|
const git_tree_entry *entry, tree_walk_data *data)
|
||||||
{
|
{
|
||||||
int retcode = GIT_ERROR;
|
int retcode = GIT_ERROR;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
git_buf contents = GIT_BUF_INIT;
|
git_buf contents = GIT_BUF_INIT;
|
||||||
|
const git_oid *id = git_tree_entry_id(entry);
|
||||||
|
int file_mode = data->opts->file_mode;
|
||||||
|
|
||||||
/* Deal with pre-existing files */
|
/* Deal with pre-existing files */
|
||||||
if (git_path_exists(git_buf_cstr(fnbuf)) &&
|
if (git_path_exists(git_buf_cstr(fnbuf)) &&
|
||||||
@ -84,10 +86,14 @@ static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
|
|||||||
}
|
}
|
||||||
if (retcode < 0) goto bctf_cleanup;
|
if (retcode < 0) goto bctf_cleanup;
|
||||||
|
|
||||||
|
/* Allow overriding of file mode */
|
||||||
|
if (!file_mode)
|
||||||
|
file_mode = git_tree_entry_attributes(entry);
|
||||||
|
|
||||||
if ((retcode = git_futils_mkpath2file(git_buf_cstr(fnbuf), data->opts->dir_mode)) < 0)
|
if ((retcode = git_futils_mkpath2file(git_buf_cstr(fnbuf), data->opts->dir_mode)) < 0)
|
||||||
goto bctf_cleanup;
|
goto bctf_cleanup;
|
||||||
|
|
||||||
fd = p_open(git_buf_cstr(fnbuf), data->opts->file_open_flags, data->opts->file_mode);
|
fd = p_open(git_buf_cstr(fnbuf), data->opts->file_open_flags, file_mode);
|
||||||
if (fd < 0) goto bctf_cleanup;
|
if (fd < 0) goto bctf_cleanup;
|
||||||
|
|
||||||
if (!p_write(fd, git_buf_cstr(&contents), git_buf_len(&contents)))
|
if (!p_write(fd, git_buf_cstr(&contents), git_buf_len(&contents)))
|
||||||
@ -129,8 +135,7 @@ static int checkout_walker(const char *path, const git_tree_entry *entry, void *
|
|||||||
retcode = blob_contents_to_link(data, &fnbuf,
|
retcode = blob_contents_to_link(data, &fnbuf,
|
||||||
git_tree_entry_id(entry));
|
git_tree_entry_id(entry));
|
||||||
} else {
|
} else {
|
||||||
retcode = blob_contents_to_file(data->repo, &fnbuf,
|
retcode = blob_contents_to_file(data->repo, &fnbuf, entry, data);
|
||||||
git_tree_entry_id(entry), data);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -163,8 +168,6 @@ int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer
|
|||||||
opts->existing_file_action = GIT_CHECKOUT_OVERWRITE_EXISTING;
|
opts->existing_file_action = GIT_CHECKOUT_OVERWRITE_EXISTING;
|
||||||
/* opts->disable_filters is false by default */
|
/* opts->disable_filters is false by default */
|
||||||
if (!opts->dir_mode) opts->dir_mode = GIT_DIR_MODE;
|
if (!opts->dir_mode) opts->dir_mode = GIT_DIR_MODE;
|
||||||
if (!opts->file_mode)
|
|
||||||
opts->file_mode = 0644;
|
|
||||||
if (!opts->file_open_flags)
|
if (!opts->file_open_flags)
|
||||||
opts->file_open_flags = O_CREAT | O_TRUNC | O_WRONLY;
|
opts->file_open_flags = O_CREAT | O_TRUNC | O_WRONLY;
|
||||||
|
|
||||||
|
@ -145,14 +145,18 @@ void test_checkout_checkout__dir_modes(void)
|
|||||||
|
|
||||||
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/dir"));
|
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/dir"));
|
||||||
|
|
||||||
opts.dir_mode = 0600;
|
opts.dir_mode = 0701;
|
||||||
cl_git_pass(git_checkout_reference(ref, &opts, NULL));
|
cl_git_pass(git_checkout_reference(ref, &opts, NULL));
|
||||||
cl_git_pass(p_stat("./testrepo/a", &st));
|
cl_git_pass(p_stat("./testrepo/a", &st));
|
||||||
cl_assert_equal_i(st.st_mode & 0777, 0600);
|
cl_assert_equal_i(st.st_mode & 0777, 0701);
|
||||||
|
|
||||||
|
/* File-mode test, since we're on the 'dir' branch */
|
||||||
|
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
|
||||||
|
cl_assert_equal_i(st.st_mode & 0777, 0755);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_checkout_checkout__file_modes(void)
|
void test_checkout_checkout__override_file_modes(void)
|
||||||
{
|
{
|
||||||
#ifndef GIT_WIN32
|
#ifndef GIT_WIN32
|
||||||
git_checkout_opts opts = {0};
|
git_checkout_opts opts = {0};
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
|||||||
cf80f8de9f1185bf3a05f993f6121880dd0cfbc9
|
144344043ba4d4a405da03de3844aa829ae8be0e
|
||||||
|
Loading…
Reference in New Issue
Block a user