View Javadoc
1   /*
2    * Copyright (C) 2012, Tomasz Zarna <tomasz.zarna@tasktop.com> 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.assertArrayEquals;
13  import static org.junit.Assert.assertEquals;
14  
15  import org.eclipse.jgit.api.Git;
16  import org.eclipse.jgit.lib.CLIRepositoryTestCase;
17  import org.junit.Test;
18  
19  public class ReflogTest extends CLIRepositoryTestCase {
20  	@Test
21  	public void testClean() throws Exception {
22  		assertArrayEquals(new String[] { "" }, execute("git reflog"));
23  	}
24  
25  	@Test
26  	public void testSingleCommit() throws Exception {
27  		try (Git git = new Git(db)) {
28  			git.commit().setMessage("initial commit").call();
29  
30  			assertEquals("6fd41be HEAD@{0}: commit (initial): initial commit",
31  					execute("git reflog")[0]);
32  		}
33  	}
34  
35  	@Test
36  	public void testBranch() throws Exception {
37  		try (Git git = new Git(db)) {
38  			git.commit().setMessage("first commit").call();
39  			git.checkout().setCreateBranch(true).setName("side").call();
40  			writeTrashFile("file", "side content");
41  			git.add().addFilepattern("file").call();
42  			git.commit().setMessage("side commit").call();
43  
44  			assertArrayEquals(new String[] {
45  					"38890c7 side@{0}: commit: side commit",
46  					"d216986 side@{1}: branch: Created from commit first commit",
47  					"" }, execute("git reflog refs/heads/side"));
48  		}
49  	}
50  }