View Javadoc
1   /*
2    * Copyright (C) 2017, Matthias Sohn <matthias.sohn@sap.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.assertTrue;
14  
15  import java.io.File;
16  
17  import org.eclipse.jgit.api.Git;
18  import org.eclipse.jgit.junit.JGitTestUtil;
19  import org.eclipse.jgit.lib.CLIRepositoryTestCase;
20  import org.eclipse.jgit.util.FileUtils;
21  import org.junit.Before;
22  import org.junit.Test;
23  
24  public class LsFilesTest extends CLIRepositoryTestCase {
25  
26  	@Before
27  	@Override
28  	public void setUp() throws Exception {
29  		super.setUp();
30  		try (Git git = new Git(db)) {
31  			JGitTestUtil.writeTrashFile(db, "hello", "hello");
32  			JGitTestUtil.writeTrashFile(db, "dir", "world", "world");
33  			git.add().addFilepattern("dir").call();
34  			git.commit().setMessage("Initial commit").call();
35  
36  			JGitTestUtil.writeTrashFile(db, "hello2", "hello");
37  			git.add().addFilepattern("hello2").call();
38  			FileUtils.createSymLink(new File(db.getWorkTree(), "link"),
39  					"target");
40  			FileUtils.mkdir(new File(db.getWorkTree(), "target"));
41  			writeTrashFile("target/file", "someData");
42  			git.add().addFilepattern("target").addFilepattern("link").call();
43  			git.commit().setMessage("hello2").call();
44  
45  			JGitTestUtil.writeTrashFile(db, "staged", "x");
46  			JGitTestUtil.deleteTrashFile(db, "hello2");
47  			git.add().addFilepattern("staged").call();
48  			JGitTestUtil.writeTrashFile(db, "untracked", "untracked");
49  		}
50  	}
51  
52  	@Test
53  	public void testHelp() throws Exception {
54  		String[] result = execute("git ls-files -h");
55  		assertTrue(result[1].startsWith("jgit ls-files"));
56  	}
57  
58  	@Test
59  	public void testLsFiles() throws Exception {
60  		assertArrayEquals(new String[] { "dir/world", "hello2", "link",
61  				"staged", "target/file", "" }, execute("git ls-files"));
62  	}
63  }