aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsFilesTest.java
blob: 4259cc1215a474d64de6b0576e4f3ac83533d3e1 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (C) 2017, Matthias Sohn <matthias.sohn@sap.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.assertTrue;

import java.io.File;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;

public class LsFilesTest extends CLIRepositoryTestCase {

	@Before
	@Override
	public void setUp() throws Exception {
		super.setUp();
		try (Git git = new Git(db)) {
			JGitTestUtil.writeTrashFile(db, "hello", "hello");
			JGitTestUtil.writeTrashFile(db, "dir", "world", "world");
			git.add().addFilepattern("dir").call();
			git.commit().setMessage("Initial commit").call();

			JGitTestUtil.writeTrashFile(db, "hello2", "hello");
			git.add().addFilepattern("hello2").call();
			FileUtils.createSymLink(new File(db.getWorkTree(), "link"),
					"target");
			FileUtils.mkdir(new File(db.getWorkTree(), "target"));
			writeTrashFile("target/file", "someData");
			git.add().addFilepattern("target").addFilepattern("link").call();
			git.commit().setMessage("hello2").call();

			JGitTestUtil.writeTrashFile(db, "staged", "x");
			JGitTestUtil.deleteTrashFile(db, "hello2");
			git.add().addFilepattern("staged").call();
			JGitTestUtil.writeTrashFile(db, "untracked", "untracked");
		}
	}

	@Test
	public void testHelp() throws Exception {
		String[] result = execute("git ls-files -h");
		assertTrue(result[1].startsWith("jgit ls-files"));
	}

	@Test
	public void testLsFiles() throws Exception {
		assertArrayEquals(new String[] { "dir/world", "hello2", "link",
				"staged", "target/file", "" }, execute("git ls-files"));
	}
}