ListTags: Fix ref in TagInfo for signed/annotated tags
'Constants.R_TAGS + tag.getTagName()' was used as ref for the TagInfo, but tag.getTagName() returns the name of the tag from the tag header which might be different from the ref name. E.g. create an annotated tag refs/tags/T1 and push it twice, once as refs/tags/T1 and once as refs/tags/T2: $ git tag -a T1 $ git push refs/tags/T1:refs/tags/T1 $ git push refs/tags/T1:refs/tags/T2 In the target repository you get 2 tags with different refs (refs/tags/T1 and refs/tags/T2), but both tags have the same tag name in the header (T1). Change-Id: Ia67f9fc96926d2b98a16330c5d96b9e842417f19 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
0d3d8e5a16
commit
0ec0d19c46
@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.project;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.RestResponse;
|
import com.google.gerrit.acceptance.RestResponse;
|
||||||
@ -24,6 +25,11 @@ import com.google.gerrit.extensions.common.TagInfo;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.eclipse.jgit.api.PushCommand;
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.eclipse.jgit.transport.PushResult;
|
||||||
|
import org.eclipse.jgit.transport.RefSpec;
|
||||||
|
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -62,16 +68,30 @@ public class TagsIT extends AbstractDaemonTest {
|
|||||||
PushOneCommit.Result r2 = push2.to(git, "refs/for/master%submit");
|
PushOneCommit.Result r2 = push2.to(git, "refs/for/master%submit");
|
||||||
r2.assertOkStatus();
|
r2.assertOkStatus();
|
||||||
|
|
||||||
|
String tag3Ref = Constants.R_TAGS + "vLatest";
|
||||||
|
PushCommand pushCmd = git.push();
|
||||||
|
pushCmd.setRefSpecs(new RefSpec(tag2.name + ":" + tag3Ref));
|
||||||
|
Iterable<PushResult> r = pushCmd.call();
|
||||||
|
assertThat(Iterables.getOnlyElement(r).getRemoteUpdate(tag3Ref).getStatus())
|
||||||
|
.isEqualTo(Status.OK);
|
||||||
|
|
||||||
List<TagInfo> result =
|
List<TagInfo> result =
|
||||||
toTagInfoList(adminSession.get("/projects/" + project.get() + "/tags"));
|
toTagInfoList(adminSession.get("/projects/" + project.get() + "/tags"));
|
||||||
assertThat(result).hasSize(2);
|
assertThat(result).hasSize(3);
|
||||||
|
|
||||||
TagInfo t = result.get(0);
|
TagInfo t = result.get(0);
|
||||||
assertThat(t.ref).isEqualTo("refs/tags/" + tag1.name);
|
assertThat(t.ref).isEqualTo(Constants.R_TAGS + tag1.name);
|
||||||
assertThat(t.revision).isEqualTo(r1.getCommitId().getName());
|
assertThat(t.revision).isEqualTo(r1.getCommitId().getName());
|
||||||
|
|
||||||
t = result.get(1);
|
t = result.get(1);
|
||||||
assertThat(t.ref).isEqualTo("refs/tags/" + tag2.name);
|
assertThat(t.ref).isEqualTo(Constants.R_TAGS + tag2.name);
|
||||||
|
assertThat(t.object).isEqualTo(r2.getCommitId().getName());
|
||||||
|
assertThat(t.message).isEqualTo(tag2.message);
|
||||||
|
assertThat(t.tagger.name).isEqualTo(tag2.tagger.getName());
|
||||||
|
assertThat(t.tagger.email).isEqualTo(tag2.tagger.getEmailAddress());
|
||||||
|
|
||||||
|
t = result.get(2);
|
||||||
|
assertThat(t.ref).isEqualTo(tag3Ref);
|
||||||
assertThat(t.object).isEqualTo(r2.getCommitId().getName());
|
assertThat(t.object).isEqualTo(r2.getCommitId().getName());
|
||||||
assertThat(t.message).isEqualTo(tag2.message);
|
assertThat(t.message).isEqualTo(tag2.message);
|
||||||
assertThat(t.tagger.name).isEqualTo(tag2.tagger.getName());
|
assertThat(t.tagger.name).isEqualTo(tag2.tagger.getName());
|
||||||
|
@ -135,7 +135,7 @@ public class ListTags implements RestReadView<ProjectResource> {
|
|||||||
RevTag tag = (RevTag)object;
|
RevTag tag = (RevTag)object;
|
||||||
// Annotated or signed tag
|
// Annotated or signed tag
|
||||||
return new TagInfo(
|
return new TagInfo(
|
||||||
Constants.R_TAGS + tag.getTagName(),
|
ref.getName(),
|
||||||
tag.getName(),
|
tag.getName(),
|
||||||
tag.getObject().getName(),
|
tag.getObject().getName(),
|
||||||
tag.getFullMessage().trim(),
|
tag.getFullMessage().trim(),
|
||||||
|
Loading…
Reference in New Issue
Block a user