vendor/libgit2/src/worktree.c in rugged-0.28.5 vs vendor/libgit2/src/worktree.c in rugged-0.99.0

- old
+ new

@@ -32,11 +32,11 @@ int git_worktree_list(git_strarray *wts, git_repository *repo) { git_vector worktrees = GIT_VECTOR_INIT; git_buf path = GIT_BUF_INIT; char *worktree; - unsigned i, len; + size_t i, len; int error; assert(wts && repo); wts->count = 0; @@ -236,40 +236,46 @@ { assert(wt); if (!is_worktree_dir(wt->gitdir_path)) { git_error_set(GIT_ERROR_WORKTREE, - "Worktree gitdir ('%s') is not valid", + "worktree gitdir ('%s') is not valid", wt->gitlink_path); return GIT_ERROR; } if (wt->parent_path && !git_path_exists(wt->parent_path)) { git_error_set(GIT_ERROR_WORKTREE, - "Worktree parent directory ('%s') does not exist ", + "worktree parent directory ('%s') does not exist ", wt->parent_path); return GIT_ERROR; } if (!git_path_exists(wt->commondir_path)) { git_error_set(GIT_ERROR_WORKTREE, - "Worktree common directory ('%s') does not exist ", + "worktree common directory ('%s') does not exist ", wt->commondir_path); return GIT_ERROR; } return 0; } -int git_worktree_add_init_options(git_worktree_add_options *opts, +int git_worktree_add_options_init(git_worktree_add_options *opts, unsigned int version) { GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version, git_worktree_add_options, GIT_WORKTREE_ADD_OPTIONS_INIT); return 0; } +int git_worktree_add_init_options(git_worktree_add_options *opts, + unsigned int version) +{ + return git_worktree_add_options_init(opts, version); +} + int git_worktree_add(git_worktree **out, git_repository *repo, const char *name, const char *worktree, const git_worktree_add_options *opts) { git_buf gitdir = GIT_BUF_INIT, wddir = GIT_BUF_INIT, buf = GIT_BUF_INIT; @@ -288,10 +294,24 @@ assert(out && repo && name && worktree); *out = NULL; + if (wtopts.ref) { + if (!git_reference_is_branch(wtopts.ref)) { + git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch"); + err = -1; + goto out; + } + + if (git_branch_is_checked_out(wtopts.ref)) { + git_error_set(GIT_ERROR_WORKTREE, "reference is already checked out"); + err = -1; + goto out; + } + } + /* Create gitdir directory ".git/worktrees/<name>" */ if ((err = git_buf_joinpath(&gitdir, repo->commondir, "worktrees")) < 0) goto out; if (!git_path_exists(gitdir.ptr)) if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) @@ -340,22 +360,10 @@ || (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0) goto out; /* Set up worktree reference */ if (wtopts.ref) { - if (!git_reference_is_branch(wtopts.ref)) { - git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch"); - err = -1; - goto out; - } - - if (git_branch_is_checked_out(wtopts.ref)) { - git_error_set(GIT_ERROR_WORKTREE, "reference is already checked out"); - err = -1; - goto out; - } - if ((err = git_reference_dup(&ref, wtopts.ref)) < 0) goto out; } else { if ((err = git_repository_head(&head, repo)) < 0) goto out; @@ -474,19 +482,25 @@ { assert(wt); return wt->worktree_path; } -int git_worktree_prune_init_options( +int git_worktree_prune_options_init( git_worktree_prune_options *opts, unsigned int version) { GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version, git_worktree_prune_options, GIT_WORKTREE_PRUNE_OPTIONS_INIT); return 0; } +int git_worktree_pruneinit_options(git_worktree_prune_options *opts, + unsigned int version) +{ + return git_worktree_prune_options_init(opts, version); +} + int git_worktree_is_prunable(git_worktree *wt, git_worktree_prune_options *opts) { git_buf reason = GIT_BUF_INIT; git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; @@ -501,20 +515,20 @@ if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0 && git_worktree_is_locked(&reason, wt)) { if (!reason.size) git_buf_attach_notowned(&reason, "no reason given", 15); - git_error_set(GIT_ERROR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr); + git_error_set(GIT_ERROR_WORKTREE, "not pruning locked working tree: '%s'", reason.ptr); git_buf_dispose(&reason); return 0; } if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 && git_worktree_validate(wt) == 0) { - git_error_set(GIT_ERROR_WORKTREE, "Not pruning valid working tree"); + git_error_set(GIT_ERROR_WORKTREE, "not pruning valid working tree"); return 0; } return 1; } @@ -542,11 +556,11 @@ /* Delete gitdir in parent repository */ if ((err = git_buf_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name)) < 0) goto out; if (!git_path_exists(path.ptr)) { - git_error_set(GIT_ERROR_WORKTREE, "Worktree gitdir '%s' does not exist", path.ptr); + git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir '%s' does not exist", path.ptr); err = -1; goto out; } if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0) goto out; @@ -562,10 +576,10 @@ if ((wtpath = git_path_dirname(wt->gitlink_path)) == NULL) goto out; git_buf_attach(&path, wtpath, 0); if (!git_path_exists(path.ptr)) { - git_error_set(GIT_ERROR_WORKTREE, "Working tree '%s' does not exist", path.ptr); + git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr); err = -1; goto out; } if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0) goto out;