Browse Source

Merge branch 'jk/push-to-delete'

* jk/push-to-delete:
  builtin-push: add --delete as syntactic sugar for :foo
maint
Junio C Hamano 15 years ago
parent
commit
84d52cabe7
  1. 4
      Documentation/git-push.txt
  2. 26
      builtin-push.c
  3. 26
      t/t5516-fetch-push.sh

4
Documentation/git-push.txt

@ -91,6 +91,10 @@ nor in any Push line of the corresponding remotes file---see below). @@ -91,6 +91,10 @@ nor in any Push line of the corresponding remotes file---see below).
will be tab-separated and sent to stdout instead of stderr. The full
symbolic names of the refs will be given.

--delete::
All listed refs are deleted from the remote repository. This is
the same as prefixing all refs with a colon.

--tags::
All refs under `$GIT_DIR/refs/tags` are pushed, in
addition to refspecs explicitly listed on the command

26
builtin-push.c

@ -15,6 +15,7 @@ static const char * const push_usage[] = { @@ -15,6 +15,7 @@ static const char * const push_usage[] = {
};

static int thin;
static int deleterefs;
static const char *receivepack;

static const char **refspec;
@ -39,11 +40,24 @@ static void set_refspecs(const char **refs, int nr) @@ -39,11 +40,24 @@ static void set_refspecs(const char **refs, int nr)
if (nr <= ++i)
die("tag shorthand without <tag>");
len = strlen(refs[i]) + 11;
tag = xmalloc(len);
strcpy(tag, "refs/tags/");
if (deleterefs) {
tag = xmalloc(len+1);
strcpy(tag, ":refs/tags/");
} else {
tag = xmalloc(len);
strcpy(tag, "refs/tags/");
}
strcat(tag, refs[i]);
ref = tag;
}
} else if (deleterefs && !strchr(ref, ':')) {
char *delref;
int len = strlen(ref)+1;
delref = xmalloc(len);
strcpy(delref, ":");
strcat(delref, ref);
ref = delref;
} else if (deleterefs)
die("--delete only accepts plain target ref names");
add_refspec(ref);
}
}
@ -196,6 +210,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) @@ -196,6 +210,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
OPT_BIT( 0 , "all", &flags, "push all refs", TRANSPORT_PUSH_ALL),
OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
(TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
OPT_BOOLEAN( 0, "delete", &deleterefs, "delete refs"),
OPT_BOOLEAN( 0 , "tags", &tags, "push tags (can't be used with --all or --mirror)"),
OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
OPT_BIT( 0, "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
@ -209,6 +224,11 @@ int cmd_push(int argc, const char **argv, const char *prefix) @@ -209,6 +224,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, push_usage, 0);

if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
die("--delete is incompatible with --all, --mirror and --tags");
if (deleterefs && argc < 2)
die("--delete doesn't make sense without any refs");

if (tags)
add_refspec("refs/tags/*");


26
t/t5516-fetch-push.sh

@ -547,6 +547,32 @@ test_expect_success 'allow deleting an invalid remote ref' ' @@ -547,6 +547,32 @@ test_expect_success 'allow deleting an invalid remote ref' '

'

test_expect_success 'allow deleting a ref using --delete' '
mk_test heads/master &&
(cd testrepo && git config receive.denyDeleteCurrent warn) &&
git push testrepo --delete master &&
(cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
'

test_expect_success 'allow deleting a tag using --delete' '
mk_test heads/master &&
git tag -a -m dummy_message deltag heads/master &&
git push testrepo --tags &&
(cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
git push testrepo --delete tag deltag &&
(cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
'

test_expect_success 'push --delete without args aborts' '
mk_test heads/master &&
test_must_fail git push testrepo --delete
'

test_expect_success 'push --delete refuses src:dest refspecs' '
mk_test heads/master &&
test_must_fail git push testrepo --delete master:foo
'

test_expect_success 'warn on push to HEAD of non-bare repository' '
mk_test heads/master
(cd testrepo &&

Loading…
Cancel
Save