View Javadoc
1   /*
2    * Copyright (C) 2016, RĂ¼diger Herrmann <ruediger.herrmann@gmx.de> 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  
11  package org.eclipse.jgit.pgm;
12  
13  import static org.junit.Assert.assertArrayEquals;
14  import static org.junit.Assert.assertEquals;
15  
16  import java.io.File;
17  
18  import org.eclipse.jgit.internal.storage.file.FileRepository;
19  import org.eclipse.jgit.lib.CLIRepositoryTestCase;
20  import org.eclipse.jgit.lib.Constants;
21  import org.eclipse.jgit.lib.Repository;
22  import org.junit.Rule;
23  import org.junit.Test;
24  import org.junit.rules.TemporaryFolder;
25  
26  public class InitTest extends CLIRepositoryTestCase {
27  
28  	@Rule
29  	public final TemporaryFolder tempFolder = new TemporaryFolder();
30  
31  	@Test
32  	public void testInitBare() throws Exception {
33  		File directory = tempFolder.getRoot();
34  
35  		String[] result = execute(
36  				"git init '" + directory.getCanonicalPath() + "' --bare");
37  
38  		String[] expecteds = new String[] {
39  				"Initialized empty Git repository in "
40  						+ directory.getCanonicalPath(),
41  				"" };
42  		assertArrayEquals(expecteds, result);
43  	}
44  
45  	@Test
46  	public void testInitDirectory() throws Exception {
47  		File workDirectory = tempFolder.getRoot();
48  		File gitDirectory = new File(workDirectory, Constants.DOT_GIT);
49  
50  		String[] result = execute(
51  				"git init '" + workDirectory.getCanonicalPath() + "'");
52  
53  		String[] expecteds = new String[] {
54  				"Initialized empty Git repository in "
55  						+ gitDirectory.getCanonicalPath(),
56  				"" };
57  		assertArrayEquals(expecteds, result);
58  	}
59  
60  	@Test
61  	public void testInitDirectoryInitialBranch() throws Exception {
62  		File workDirectory = tempFolder.getRoot();
63  		File gitDirectory = new File(workDirectory, Constants.DOT_GIT);
64  
65  		String[] result = execute(
66  				"git init -b main '" + workDirectory.getCanonicalPath() + "'");
67  
68  		String[] expecteds = new String[] {
69  				"Initialized empty Git repository in "
70  						+ gitDirectory.getCanonicalPath(),
71  				"" };
72  		assertArrayEquals(expecteds, result);
73  
74  		try (Repository repo = new FileRepository(gitDirectory)) {
75  			assertEquals("refs/heads/main", repo.getFullBranch());
76  		}
77  	}
78  }