Merge branch 'ds/branch-checked-out' into ds/rebase-update-ref
* ds/branch-checked-out: branch: drop unused worktrees variable fetch: stop passing around unused worktrees variable branch: fix branch_checked_out() leaks branch: use branch_checked_out() when deleting refs fetch: use new branch_checked_out() and add tests branch: check for bisects and rebases branch: add branch_checked_out() helper
This commit is contained in:
commit
7fefa1b68e
76
branch.c
76
branch.c
@ -10,6 +10,7 @@
|
|||||||
#include "worktree.h"
|
#include "worktree.h"
|
||||||
#include "submodule-config.h"
|
#include "submodule-config.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
|
#include "strmap.h"
|
||||||
|
|
||||||
struct tracking {
|
struct tracking {
|
||||||
struct refspec_item spec;
|
struct refspec_item spec;
|
||||||
@ -369,6 +370,70 @@ int validate_branchname(const char *name, struct strbuf *ref)
|
|||||||
return ref_exists(ref->buf);
|
return ref_exists(ref->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int initialized_checked_out_branches;
|
||||||
|
static struct strmap current_checked_out_branches = STRMAP_INIT;
|
||||||
|
|
||||||
|
static void prepare_checked_out_branches(void)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
struct worktree **worktrees;
|
||||||
|
|
||||||
|
if (initialized_checked_out_branches)
|
||||||
|
return;
|
||||||
|
initialized_checked_out_branches = 1;
|
||||||
|
|
||||||
|
worktrees = get_worktrees();
|
||||||
|
|
||||||
|
while (worktrees[i]) {
|
||||||
|
char *old;
|
||||||
|
struct wt_status_state state = { 0 };
|
||||||
|
struct worktree *wt = worktrees[i++];
|
||||||
|
|
||||||
|
if (wt->is_bare)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (wt->head_ref) {
|
||||||
|
old = strmap_put(¤t_checked_out_branches,
|
||||||
|
wt->head_ref,
|
||||||
|
xstrdup(wt->path));
|
||||||
|
free(old);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wt_status_check_rebase(wt, &state) &&
|
||||||
|
(state.rebase_in_progress || state.rebase_interactive_in_progress) &&
|
||||||
|
state.branch) {
|
||||||
|
struct strbuf ref = STRBUF_INIT;
|
||||||
|
strbuf_addf(&ref, "refs/heads/%s", state.branch);
|
||||||
|
old = strmap_put(¤t_checked_out_branches,
|
||||||
|
ref.buf,
|
||||||
|
xstrdup(wt->path));
|
||||||
|
free(old);
|
||||||
|
strbuf_release(&ref);
|
||||||
|
}
|
||||||
|
wt_status_state_free_buffers(&state);
|
||||||
|
|
||||||
|
if (wt_status_check_bisect(wt, &state) &&
|
||||||
|
state.branch) {
|
||||||
|
struct strbuf ref = STRBUF_INIT;
|
||||||
|
strbuf_addf(&ref, "refs/heads/%s", state.branch);
|
||||||
|
old = strmap_put(¤t_checked_out_branches,
|
||||||
|
ref.buf,
|
||||||
|
xstrdup(wt->path));
|
||||||
|
free(old);
|
||||||
|
strbuf_release(&ref);
|
||||||
|
}
|
||||||
|
wt_status_state_free_buffers(&state);
|
||||||
|
}
|
||||||
|
|
||||||
|
free_worktrees(worktrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *branch_checked_out(const char *refname)
|
||||||
|
{
|
||||||
|
prepare_checked_out_branches();
|
||||||
|
return strmap_get(¤t_checked_out_branches, refname);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if a branch 'name' can be created as a new branch; die otherwise.
|
* Check if a branch 'name' can be created as a new branch; die otherwise.
|
||||||
* 'force' can be used when it is OK for the named branch already exists.
|
* 'force' can be used when it is OK for the named branch already exists.
|
||||||
@ -377,9 +442,7 @@ int validate_branchname(const char *name, struct strbuf *ref)
|
|||||||
*/
|
*/
|
||||||
int validate_new_branchname(const char *name, struct strbuf *ref, int force)
|
int validate_new_branchname(const char *name, struct strbuf *ref, int force)
|
||||||
{
|
{
|
||||||
struct worktree **worktrees;
|
const char *path;
|
||||||
const struct worktree *wt;
|
|
||||||
|
|
||||||
if (!validate_branchname(name, ref))
|
if (!validate_branchname(name, ref))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -387,13 +450,10 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
|
|||||||
die(_("a branch named '%s' already exists"),
|
die(_("a branch named '%s' already exists"),
|
||||||
ref->buf + strlen("refs/heads/"));
|
ref->buf + strlen("refs/heads/"));
|
||||||
|
|
||||||
worktrees = get_worktrees();
|
if ((path = branch_checked_out(ref->buf)))
|
||||||
wt = find_shared_symref(worktrees, "HEAD", ref->buf);
|
|
||||||
if (wt && !wt->is_bare)
|
|
||||||
die(_("cannot force update the branch '%s' "
|
die(_("cannot force update the branch '%s' "
|
||||||
"checked out at '%s'"),
|
"checked out at '%s'"),
|
||||||
ref->buf + strlen("refs/heads/"), wt->path);
|
ref->buf + strlen("refs/heads/"), path);
|
||||||
free_worktrees(worktrees);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
7
branch.h
7
branch.h
@ -101,6 +101,13 @@ void create_branches_recursively(struct repository *r, const char *name,
|
|||||||
const char *tracking_name, int force,
|
const char *tracking_name, int force,
|
||||||
int reflog, int quiet, enum branch_track track,
|
int reflog, int quiet, enum branch_track track,
|
||||||
int dry_run);
|
int dry_run);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the branch at 'refname' is currently checked out in a worktree,
|
||||||
|
* then return the path to that worktree.
|
||||||
|
*/
|
||||||
|
const char *branch_checked_out(const char *refname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if 'name' can be a valid name for a branch; die otherwise.
|
* Check if 'name' can be a valid name for a branch; die otherwise.
|
||||||
* Return 1 if the named branch already exists; return 0 otherwise.
|
* Return 1 if the named branch already exists; return 0 otherwise.
|
||||||
|
@ -204,7 +204,6 @@ static void delete_branch_config(const char *branchname)
|
|||||||
static int delete_branches(int argc, const char **argv, int force, int kinds,
|
static int delete_branches(int argc, const char **argv, int force, int kinds,
|
||||||
int quiet)
|
int quiet)
|
||||||
{
|
{
|
||||||
struct worktree **worktrees;
|
|
||||||
struct commit *head_rev = NULL;
|
struct commit *head_rev = NULL;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
@ -242,8 +241,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
|||||||
die(_("Couldn't look up commit object for HEAD"));
|
die(_("Couldn't look up commit object for HEAD"));
|
||||||
}
|
}
|
||||||
|
|
||||||
worktrees = get_worktrees();
|
|
||||||
|
|
||||||
for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
|
for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
|
||||||
char *target = NULL;
|
char *target = NULL;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
@ -253,12 +250,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
|||||||
name = mkpathdup(fmt, bname.buf);
|
name = mkpathdup(fmt, bname.buf);
|
||||||
|
|
||||||
if (kinds == FILTER_REFS_BRANCHES) {
|
if (kinds == FILTER_REFS_BRANCHES) {
|
||||||
const struct worktree *wt =
|
const char *path;
|
||||||
find_shared_symref(worktrees, "HEAD", name);
|
if ((path = branch_checked_out(name))) {
|
||||||
if (wt) {
|
|
||||||
error(_("Cannot delete branch '%s' "
|
error(_("Cannot delete branch '%s' "
|
||||||
"checked out at '%s'"),
|
"checked out at '%s'"),
|
||||||
bname.buf, wt->path);
|
bname.buf, path);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -315,7 +311,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
|||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
strbuf_release(&bname);
|
strbuf_release(&bname);
|
||||||
free_worktrees(worktrees);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -881,11 +881,9 @@ static void format_display(struct strbuf *display, char code,
|
|||||||
static int update_local_ref(struct ref *ref,
|
static int update_local_ref(struct ref *ref,
|
||||||
struct ref_transaction *transaction,
|
struct ref_transaction *transaction,
|
||||||
const char *remote, const struct ref *remote_ref,
|
const char *remote, const struct ref *remote_ref,
|
||||||
struct strbuf *display, int summary_width,
|
struct strbuf *display, int summary_width)
|
||||||
struct worktree **worktrees)
|
|
||||||
{
|
{
|
||||||
struct commit *current = NULL, *updated;
|
struct commit *current = NULL, *updated;
|
||||||
const struct worktree *wt;
|
|
||||||
const char *pretty_ref = prettify_refname(ref->name);
|
const char *pretty_ref = prettify_refname(ref->name);
|
||||||
int fast_forward = 0;
|
int fast_forward = 0;
|
||||||
|
|
||||||
@ -900,16 +898,14 @@ static int update_local_ref(struct ref *ref,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!update_head_ok &&
|
if (!update_head_ok &&
|
||||||
(wt = find_shared_symref(worktrees, "HEAD", ref->name)) &&
|
!is_null_oid(&ref->old_oid) &&
|
||||||
!wt->is_bare && !is_null_oid(&ref->old_oid)) {
|
branch_checked_out(ref->name)) {
|
||||||
/*
|
/*
|
||||||
* If this is the head, and it's not okay to update
|
* If this is the head, and it's not okay to update
|
||||||
* the head, and the old value of the head isn't empty...
|
* the head, and the old value of the head isn't empty...
|
||||||
*/
|
*/
|
||||||
format_display(display, '!', _("[rejected]"),
|
format_display(display, '!', _("[rejected]"),
|
||||||
wt->is_current ?
|
_("can't fetch into checked-out branch"),
|
||||||
_("can't fetch in current branch") :
|
|
||||||
_("checked out in another worktree"),
|
|
||||||
remote, pretty_ref, summary_width);
|
remote, pretty_ref, summary_width);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1110,7 +1106,7 @@ N_("it took %.2f seconds to check forced updates; you can use\n"
|
|||||||
static int store_updated_refs(const char *raw_url, const char *remote_name,
|
static int store_updated_refs(const char *raw_url, const char *remote_name,
|
||||||
int connectivity_checked,
|
int connectivity_checked,
|
||||||
struct ref_transaction *transaction, struct ref *ref_map,
|
struct ref_transaction *transaction, struct ref *ref_map,
|
||||||
struct fetch_head *fetch_head, struct worktree **worktrees)
|
struct fetch_head *fetch_head)
|
||||||
{
|
{
|
||||||
int url_len, i, rc = 0;
|
int url_len, i, rc = 0;
|
||||||
struct strbuf note = STRBUF_INIT, err = STRBUF_INIT;
|
struct strbuf note = STRBUF_INIT, err = STRBUF_INIT;
|
||||||
@ -1240,8 +1236,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
|
|||||||
strbuf_reset(¬e);
|
strbuf_reset(¬e);
|
||||||
if (ref) {
|
if (ref) {
|
||||||
rc |= update_local_ref(ref, transaction, what,
|
rc |= update_local_ref(ref, transaction, what,
|
||||||
rm, ¬e, summary_width,
|
rm, ¬e, summary_width);
|
||||||
worktrees);
|
|
||||||
free(ref);
|
free(ref);
|
||||||
} else if (write_fetch_head || dry_run) {
|
} else if (write_fetch_head || dry_run) {
|
||||||
/*
|
/*
|
||||||
@ -1332,8 +1327,7 @@ static int check_exist_and_connected(struct ref *ref_map)
|
|||||||
static int fetch_and_consume_refs(struct transport *transport,
|
static int fetch_and_consume_refs(struct transport *transport,
|
||||||
struct ref_transaction *transaction,
|
struct ref_transaction *transaction,
|
||||||
struct ref *ref_map,
|
struct ref *ref_map,
|
||||||
struct fetch_head *fetch_head,
|
struct fetch_head *fetch_head)
|
||||||
struct worktree **worktrees)
|
|
||||||
{
|
{
|
||||||
int connectivity_checked = 1;
|
int connectivity_checked = 1;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1356,7 +1350,7 @@ static int fetch_and_consume_refs(struct transport *transport,
|
|||||||
trace2_region_enter("fetch", "consume_refs", the_repository);
|
trace2_region_enter("fetch", "consume_refs", the_repository);
|
||||||
ret = store_updated_refs(transport->url, transport->remote->name,
|
ret = store_updated_refs(transport->url, transport->remote->name,
|
||||||
connectivity_checked, transaction, ref_map,
|
connectivity_checked, transaction, ref_map,
|
||||||
fetch_head, worktrees);
|
fetch_head);
|
||||||
trace2_region_leave("fetch", "consume_refs", the_repository);
|
trace2_region_leave("fetch", "consume_refs", the_repository);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -1434,19 +1428,16 @@ cleanup:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_not_current_branch(struct ref *ref_map,
|
static void check_not_current_branch(struct ref *ref_map)
|
||||||
struct worktree **worktrees)
|
|
||||||
{
|
{
|
||||||
const struct worktree *wt;
|
const char *path;
|
||||||
for (; ref_map; ref_map = ref_map->next)
|
for (; ref_map; ref_map = ref_map->next)
|
||||||
if (ref_map->peer_ref &&
|
if (ref_map->peer_ref &&
|
||||||
starts_with(ref_map->peer_ref->name, "refs/heads/") &&
|
starts_with(ref_map->peer_ref->name, "refs/heads/") &&
|
||||||
(wt = find_shared_symref(worktrees, "HEAD",
|
(path = branch_checked_out(ref_map->peer_ref->name)))
|
||||||
ref_map->peer_ref->name)) &&
|
|
||||||
!wt->is_bare)
|
|
||||||
die(_("refusing to fetch into branch '%s' "
|
die(_("refusing to fetch into branch '%s' "
|
||||||
"checked out at '%s'"),
|
"checked out at '%s'"),
|
||||||
ref_map->peer_ref->name, wt->path);
|
ref_map->peer_ref->name, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int truncate_fetch_head(void)
|
static int truncate_fetch_head(void)
|
||||||
@ -1549,8 +1540,7 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
|
|||||||
static int backfill_tags(struct transport *transport,
|
static int backfill_tags(struct transport *transport,
|
||||||
struct ref_transaction *transaction,
|
struct ref_transaction *transaction,
|
||||||
struct ref *ref_map,
|
struct ref *ref_map,
|
||||||
struct fetch_head *fetch_head,
|
struct fetch_head *fetch_head)
|
||||||
struct worktree **worktrees)
|
|
||||||
{
|
{
|
||||||
int retcode, cannot_reuse;
|
int retcode, cannot_reuse;
|
||||||
|
|
||||||
@ -1571,7 +1561,7 @@ static int backfill_tags(struct transport *transport,
|
|||||||
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
|
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
|
||||||
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
|
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
|
||||||
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
|
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
|
||||||
retcode = fetch_and_consume_refs(transport, transaction, ref_map, fetch_head, worktrees);
|
retcode = fetch_and_consume_refs(transport, transaction, ref_map, fetch_head);
|
||||||
|
|
||||||
if (gsecondary) {
|
if (gsecondary) {
|
||||||
transport_disconnect(gsecondary);
|
transport_disconnect(gsecondary);
|
||||||
@ -1592,7 +1582,6 @@ static int do_fetch(struct transport *transport,
|
|||||||
struct transport_ls_refs_options transport_ls_refs_options =
|
struct transport_ls_refs_options transport_ls_refs_options =
|
||||||
TRANSPORT_LS_REFS_OPTIONS_INIT;
|
TRANSPORT_LS_REFS_OPTIONS_INIT;
|
||||||
int must_list_refs = 1;
|
int must_list_refs = 1;
|
||||||
struct worktree **worktrees = get_worktrees();
|
|
||||||
struct fetch_head fetch_head = { 0 };
|
struct fetch_head fetch_head = { 0 };
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
@ -1650,7 +1639,7 @@ static int do_fetch(struct transport *transport,
|
|||||||
ref_map = get_ref_map(transport->remote, remote_refs, rs,
|
ref_map = get_ref_map(transport->remote, remote_refs, rs,
|
||||||
tags, &autotags);
|
tags, &autotags);
|
||||||
if (!update_head_ok)
|
if (!update_head_ok)
|
||||||
check_not_current_branch(ref_map, worktrees);
|
check_not_current_branch(ref_map);
|
||||||
|
|
||||||
retcode = open_fetch_head(&fetch_head);
|
retcode = open_fetch_head(&fetch_head);
|
||||||
if (retcode)
|
if (retcode)
|
||||||
@ -1683,7 +1672,7 @@ static int do_fetch(struct transport *transport,
|
|||||||
retcode = 1;
|
retcode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetch_and_consume_refs(transport, transaction, ref_map, &fetch_head, worktrees)) {
|
if (fetch_and_consume_refs(transport, transaction, ref_map, &fetch_head)) {
|
||||||
retcode = 1;
|
retcode = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1706,7 +1695,7 @@ static int do_fetch(struct transport *transport,
|
|||||||
* the transaction and don't commit anything.
|
* the transaction and don't commit anything.
|
||||||
*/
|
*/
|
||||||
if (backfill_tags(transport, transaction, tags_ref_map,
|
if (backfill_tags(transport, transaction, tags_ref_map,
|
||||||
&fetch_head, worktrees))
|
&fetch_head))
|
||||||
retcode = 1;
|
retcode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1791,7 +1780,6 @@ cleanup:
|
|||||||
close_fetch_head(&fetch_head);
|
close_fetch_head(&fetch_head);
|
||||||
strbuf_release(&err);
|
strbuf_release(&err);
|
||||||
free_refs(ref_map);
|
free_refs(ref_map);
|
||||||
free_worktrees(worktrees);
|
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
129
t/t2407-worktree-heads.sh
Executable file
129
t/t2407-worktree-heads.sh
Executable file
@ -0,0 +1,129 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test operations trying to overwrite refs at worktree HEAD'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
test_commit init &&
|
||||||
|
git branch -f fake-1 &&
|
||||||
|
git branch -f fake-2 &&
|
||||||
|
|
||||||
|
for i in 1 2 3 4
|
||||||
|
do
|
||||||
|
test_commit $i &&
|
||||||
|
git branch wt-$i &&
|
||||||
|
git worktree add wt-$i wt-$i || return 1
|
||||||
|
done &&
|
||||||
|
|
||||||
|
# Create a server that updates each branch by one commit
|
||||||
|
git init server &&
|
||||||
|
test_commit -C server initial &&
|
||||||
|
git remote add server ./server &&
|
||||||
|
for i in 1 2 3 4
|
||||||
|
do
|
||||||
|
git -C server checkout -b wt-$i &&
|
||||||
|
test_commit -C server A-$i || return 1
|
||||||
|
done &&
|
||||||
|
for i in 1 2
|
||||||
|
do
|
||||||
|
git -C server checkout -b fake-$i &&
|
||||||
|
test_commit -C server f-$i || return 1
|
||||||
|
done
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refuse to overwrite: checked out in worktree' '
|
||||||
|
for i in 1 2 3 4
|
||||||
|
do
|
||||||
|
test_must_fail git branch -f wt-$i HEAD 2>err
|
||||||
|
grep "cannot force update the branch" err &&
|
||||||
|
|
||||||
|
test_must_fail git branch -D wt-$i 2>err
|
||||||
|
grep "Cannot delete branch" err || return 1
|
||||||
|
done
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refuse to overwrite: worktree in bisect' '
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
|
||||||
|
|
||||||
|
touch .git/worktrees/wt-4/BISECT_LOG &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
|
||||||
|
|
||||||
|
test_must_fail git branch -f fake-2 HEAD 2>err &&
|
||||||
|
grep "cannot force update the branch '\''fake-2'\'' checked out at.*wt-4" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refuse to overwrite: worktree in rebase' '
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
|
||||||
|
|
||||||
|
mkdir -p .git/worktrees/wt-3/rebase-merge &&
|
||||||
|
touch .git/worktrees/wt-3/rebase-merge/interactive &&
|
||||||
|
echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto &&
|
||||||
|
|
||||||
|
test_must_fail git branch -f fake-1 HEAD 2>err &&
|
||||||
|
grep "cannot force update the branch '\''fake-1'\'' checked out at.*wt-3" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' '
|
||||||
|
test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err &&
|
||||||
|
grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err &&
|
||||||
|
|
||||||
|
# General fetch into refs/heads/ will fail on first ref,
|
||||||
|
# so use a generic error message check.
|
||||||
|
test_must_fail git fetch server +refs/heads/*:refs/heads/* 2>err &&
|
||||||
|
grep "refusing to fetch into branch" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' '
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
|
||||||
|
|
||||||
|
touch .git/worktrees/wt-4/BISECT_LOG &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
|
||||||
|
|
||||||
|
test_must_fail git fetch server +refs/heads/fake-2:refs/heads/fake-2 2>err &&
|
||||||
|
grep "refusing to fetch into branch" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' '
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
|
||||||
|
|
||||||
|
mkdir -p .git/worktrees/wt-4/rebase-merge &&
|
||||||
|
touch .git/worktrees/wt-4/rebase-merge/interactive &&
|
||||||
|
echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/head-name &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/onto &&
|
||||||
|
|
||||||
|
test_must_fail git fetch server +refs/heads/fake-1:refs/heads/fake-1 2>err &&
|
||||||
|
grep "refusing to fetch into branch" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refuse to overwrite when in error states' '
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
|
||||||
|
test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
|
||||||
|
|
||||||
|
# Both branches are currently under rebase.
|
||||||
|
mkdir -p .git/worktrees/wt-3/rebase-merge &&
|
||||||
|
touch .git/worktrees/wt-3/rebase-merge/interactive &&
|
||||||
|
echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto &&
|
||||||
|
mkdir -p .git/worktrees/wt-4/rebase-merge &&
|
||||||
|
touch .git/worktrees/wt-4/rebase-merge/interactive &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/head-name &&
|
||||||
|
echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/onto &&
|
||||||
|
|
||||||
|
# Both branches are currently under bisect.
|
||||||
|
touch .git/worktrees/wt-4/BISECT_LOG &&
|
||||||
|
echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
|
||||||
|
touch .git/worktrees/wt-1/BISECT_LOG &&
|
||||||
|
echo refs/heads/fake-1 >.git/worktrees/wt-1/BISECT_START &&
|
||||||
|
|
||||||
|
for i in 1 2
|
||||||
|
do
|
||||||
|
test_must_fail git branch -f fake-$i HEAD 2>err &&
|
||||||
|
grep "cannot force update the branch '\''fake-$i'\'' checked out at" err ||
|
||||||
|
return 1
|
||||||
|
done
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user