aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ReflogTest.java
blob: 1423887de91e9ad136ef0fb849ba2bd9443048a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (C) 2012, Tomasz Zarna <tomasz.zarna@tasktop.com> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.pgm;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.junit.Test;

public class ReflogTest extends CLIRepositoryTestCase {
	@Test
	public void testClean() throws Exception {
		assertArrayEquals(new String[] { "" }, execute("git reflog"));
	}

	@Test
	public void testSingleCommit() throws Exception {
		try (Git git = new Git(db)) {
			git.commit().setMessage("initial commit").call();

			assertEquals("6fd41be HEAD@{0}: commit (initial): initial commit",
					execute("git reflog")[0]);
		}
	}

	@Test
	public void testBranch() throws Exception {
		try (Git git = new Git(db)) {
			git.commit().setMessage("first commit").call();
			git.checkout().setCreateBranch(true).setName("side").call();
			writeTrashFile("file", "side content");
			git.add().addFilepattern("file").call();
			git.commit().setMessage("side commit").call();

			assertArrayEquals(new String[] {
					"38890c7 side@{0}: commit: side commit",
					"d216986 side@{1}: branch: Created from commit first commit",
					"" }, execute("git reflog refs/heads/side"));
		}
	}
}