-
Notifications
You must be signed in to change notification settings - Fork 165
[GSoC] receive.denyCurrentBranch: respect all worktrees #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| #include "object-store.h" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): |
||
| #include "protocol.h" | ||
| #include "commit-reach.h" | ||
| #include "worktree.h" | ||
|
|
||
| static const char * const receive_pack_usage[] = { | ||
| N_("git receive-pack <git-dir>"), | ||
|
|
@@ -816,16 +817,6 @@ static int run_update_hook(struct command *cmd) | |
| return finish_command(&proc); | ||
| } | ||
|
|
||
| static int is_ref_checked_out(const char *ref) | ||
| { | ||
| if (is_bare_repository()) | ||
| return 0; | ||
|
|
||
| if (!head_name) | ||
| return 0; | ||
| return !strcmp(head_name, ref); | ||
| } | ||
|
|
||
| static char *refuse_unconfigured_deny_msg = | ||
| N_("By default, updating the current branch in a non-bare repository\n" | ||
| "is denied, because it will make the index and work tree inconsistent\n" | ||
|
|
@@ -997,16 +988,27 @@ static const char *push_to_checkout(unsigned char *hash, | |
| return NULL; | ||
| } | ||
|
|
||
| static const char *update_worktree(unsigned char *sha1) | ||
| static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree) | ||
| { | ||
| const char *retval; | ||
| const char *work_tree = git_work_tree_cfg ? git_work_tree_cfg : ".."; | ||
| const char *retval, *work_tree, *git_dir = NULL; | ||
| struct argv_array env = ARGV_ARRAY_INIT; | ||
|
|
||
| if (worktree && worktree->path) | ||
| work_tree = worktree->path; | ||
| else if (git_work_tree_cfg) | ||
| work_tree = git_work_tree_cfg; | ||
| else | ||
| work_tree = ".."; | ||
|
|
||
| if (is_bare_repository()) | ||
| return "denyCurrentBranch = updateInstead needs a worktree"; | ||
|
|
||
| if (worktree) | ||
| git_dir = get_worktree_git_dir(worktree); | ||
| if (!git_dir) | ||
| git_dir = get_git_dir(); | ||
|
|
||
| argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(get_git_dir())); | ||
| argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); | ||
|
|
||
| if (!find_hook(push_to_checkout_hook)) | ||
| retval = push_to_deploy(sha1, &env, work_tree); | ||
|
|
@@ -1026,6 +1028,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) | |
| struct object_id *old_oid = &cmd->old_oid; | ||
| struct object_id *new_oid = &cmd->new_oid; | ||
| int do_update_worktree = 0; | ||
| const struct worktree *worktree = is_bare_repository() ? NULL : find_shared_symref("HEAD", name); | ||
|
|
||
| /* only refs/... are allowed */ | ||
| if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) { | ||
|
|
@@ -1037,7 +1040,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) | |
| free(namespaced_name); | ||
| namespaced_name = strbuf_detach(&namespaced_name_buf, NULL); | ||
|
|
||
| if (is_ref_checked_out(namespaced_name)) { | ||
| if (worktree) { | ||
| switch (deny_current_branch) { | ||
| case DENY_IGNORE: | ||
| break; | ||
|
|
@@ -1069,7 +1072,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) | |
| return "deletion prohibited"; | ||
| } | ||
|
|
||
| if (head_name && !strcmp(namespaced_name, head_name)) { | ||
| if (worktree || (head_name && !strcmp(namespaced_name, head_name))) { | ||
| switch (deny_delete_current) { | ||
| case DENY_IGNORE: | ||
| break; | ||
|
|
@@ -1118,7 +1121,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) | |
| } | ||
|
|
||
| if (do_update_worktree) { | ||
| ret = update_worktree(new_oid->hash); | ||
| ret = update_worktree(new_oid->hash, find_shared_symref("HEAD", name)); | ||
harry-hov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (ret) | ||
| return ret; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ test_expect_success setup ' | |
| ) && | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Hariom verma wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Hariom verma wrote (reply to this):
harry-hov marked this conversation as resolved.
Show resolved
Hide resolved
harry-hov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| commit0=$(cd original && git rev-parse HEAD^) && | ||
| commit1=$(cd original && git rev-parse HEAD) && | ||
| git init pushee && | ||
| git init --bare pushee && | ||
dscho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| git init puller | ||
| ' | ||
|
|
||
|
|
@@ -152,4 +152,15 @@ test_expect_success 'clone chooses correct HEAD (v2)' ' | |
| test_cmp expect actual | ||
| ' | ||
|
|
||
| test_expect_success 'denyCurrentBranch and unborn branch with ref namespace' ' | ||
| ( | ||
| cd original && | ||
| git init unborn && | ||
| git remote add unborn-namespaced "ext::git --namespace=namespace %s unborn" && | ||
| test_must_fail git push unborn-namespaced HEAD:master && | ||
| git -C unborn config receive.denyCurrentBranch updateInstead && | ||
| git push unborn-namespaced HEAD:master | ||
| ) | ||
| ' | ||
|
|
||
| test_done | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ static struct worktree *get_main_worktree(void) | |
| struct strbuf worktree_path = STRBUF_INIT; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Hariom verma wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this): |
||
|
|
||
| strbuf_add_absolute_path(&worktree_path, get_git_common_dir()); | ||
| strbuf_strip_suffix(&worktree_path, "/."); | ||
| if (!strbuf_strip_suffix(&worktree_path, "/.git")) | ||
| strbuf_strip_suffix(&worktree_path, "/."); | ||
dscho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.