View Javadoc
1   /*
2    * Copyright (C) 2012, Tomasz Zarna <tomasz.zarna@tasktop.com> and others. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.pgm;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertNull;
15  
16  import org.eclipse.jgit.api.Git;
17  import org.eclipse.jgit.lib.CLIRepositoryTestCase;
18  import org.junit.Before;
19  import org.junit.Test;
20  
21  public class TagTest extends CLIRepositoryTestCase {
22  	private Git git;
23  
24  	@Override
25  	@Before
26  	public void setUp() throws Exception {
27  		super.setUp();
28  		git = new Git(db);
29  		git.commit().setMessage("initial commit").call();
30  	}
31  
32  	@Test
33  	public void testTagTwice() throws Exception {
34  		git.tag().setName("test").call();
35  		writeTrashFile("file", "content");
36  		git.add().addFilepattern("file").call();
37  		git.commit().setMessage("commit").call();
38  
39  		assertEquals("fatal: tag 'test' already exists",
40  				executeUnchecked("git tag test")[0]);
41  	}
42  
43  	@Test
44  	public void testTagDelete() throws Exception {
45  		git.tag().setName("test").call();
46  		assertNotNull(git.getRepository().exactRef("refs/tags/test"));
47  		assertEquals("", executeUnchecked("git tag -d test")[0]);
48  		assertNull(git.getRepository().exactRef("refs/tags/test"));
49  	}
50  
51  	@Test
52  	public void testTagDeleteFail() throws Exception {
53  		try {
54  			assertEquals("fatal: error: tag 'test' not found.",
55  					executeUnchecked("git tag -d test")[0]);
56  		} catch (Die e) {
57  			assertEquals("fatal: error: tag 'test' not found", e.getMessage());
58  		}
59  	}
60  }