1 /*******************************************************************************
2 * Copyright (C) 2010, 2012 Chris Aniszczyk <caniszczyk@gmail.com> and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.core
.test
.op
;
11 import static org
.junit
.Assert
.assertFalse
;
12 import static org
.junit
.Assert
.assertTrue
;
13 import static org
.junit
.Assert
.fail
;
17 import org
.eclipse
.core
.resources
.IProject
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
20 import org
.eclipse
.egit
.core
.op
.TagOperation
;
21 import org
.eclipse
.egit
.core
.test
.DualRepositoryTestCase
;
22 import org
.eclipse
.egit
.core
.test
.TestRepository
;
23 import org
.eclipse
.egit
.core
.test
.TestUtils
;
24 import org
.eclipse
.jgit
.lib
.Constants
;
25 import org
.eclipse
.jgit
.lib
.Ref
;
26 import org
.eclipse
.jgit
.lib
.TagBuilder
;
27 import org
.eclipse
.jgit
.revwalk
.RevTag
;
28 import org
.eclipse
.jgit
.revwalk
.RevWalk
;
29 import org
.eclipse
.jgit
.util
.RawParseUtils
;
30 import org
.junit
.After
;
31 import org
.junit
.Before
;
32 import org
.junit
.Test
;
34 public class TagOperationTest
extends DualRepositoryTestCase
{
38 String projectName
= "TagTest";
43 public void setUp() throws Exception
{
45 workdir
= testUtils
.createTempDir("Repository1");
47 repository1
= new TestRepository(new File(workdir
, Constants
.DOT_GIT
));
49 project
= testUtils
.createProjectInLocalFileSystem(workdir
,
51 testUtils
.addFileToProject(project
, "folder1/file1.txt", "Hello world");
53 repository1
.connect(project
);
54 repository1
.trackAllFiles(project
);
55 repository1
.commit("Initial commit");
59 public void tearDown() throws Exception
{
61 project
.delete(false, false, null);
63 // repositories and tempDirs are deleted in superclass
67 public void addTag() throws Exception
{
68 assertTrue("Tags should be empty", repository1
.getRepository()
69 .getTags().isEmpty());
70 TagBuilder newTag
= new TagBuilder();
71 newTag
.setTag("TheNewTag");
72 newTag
.setMessage("Well, I'm the tag");
73 newTag
.setTagger(RawParseUtils
.parsePersonIdent(TestUtils
.AUTHOR
));
74 newTag
.setObjectId(repository1
.getRepository()
75 .resolve("refs/heads/master"), Constants
.OBJ_COMMIT
);
76 TagOperation top
= new TagOperation(repository1
.getRepository(),
78 top
.execute(new NullProgressMonitor());
79 assertFalse("Tags should not be empty", repository1
.getRepository()
80 .getTags().isEmpty());
84 fail("Expected Exception not thrown");
85 } catch (CoreException e
) {
89 top
= new TagOperation(repository1
.getRepository(), newTag
, true);
92 fail("Expected Exception not thrown");
93 } catch (CoreException e
) {
96 Ref tagRef
= repository1
.getRepository().getTags().get("TheNewTag");
97 try (RevWalk walk
= new RevWalk(repository1
.getRepository())) {
98 RevTag tag
= walk
.parseTag(repository1
.getRepository().resolve(
101 newTag
.setMessage("Another message");
102 assertFalse("Messages should differ",
103 tag
.getFullMessage().equals(newTag
.getMessage()));
105 tag
= walk
.parseTag(repository1
.getRepository().resolve(
107 assertTrue("Messages be same",
108 tag
.getFullMessage().equals(newTag
.getMessage()));