View Javadoc
1   /*
2    * Copyright (C) 2012, 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.assertEquals;
13  import static org.junit.Assert.assertTrue;
14  
15  import java.util.Arrays;
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import org.eclipse.jgit.api.Git;
20  import org.eclipse.jgit.lib.CLIRepositoryTestCase;
21  import org.eclipse.jgit.util.SystemReader;
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  public class ConfigTest extends CLIRepositoryTestCase {
26  	@Override
27  	@Before
28  	public void setUp() throws Exception {
29  		super.setUp();
30  		try (Git git = new Git(db)) {
31  			git.commit().setMessage("initial commit").call();
32  		}
33  	}
34  
35  	@SuppressWarnings("boxing")
36  	@Test
37  	public void testListConfig() throws Exception {
38  		boolean isWindows = SystemReader.getInstance().getProperty("os.name")
39  				.startsWith("Windows");
40  		boolean isMac = SystemReader.getInstance().getProperty("os.name")
41  				.equals("Mac OS X");
42  
43  		String[] output = execute("git config --list");
44  
45  		Map<String, String> options = parseOptions(output);
46  
47  		assertEquals(!isWindows, Boolean.valueOf(options.get("core.filemode")));
48  		assertTrue((Boolean.valueOf(options.get("core.logallrefupdates"))));
49  		if (isMac) {
50  			assertTrue(
51  					(Boolean.valueOf(options.get("core.precomposeunicode"))));
52  		}
53  		assertEquals(Integer.valueOf(0),
54  				Integer.valueOf(options.get("core.repositoryformatversion")));
55  	}
56  
57  	private Map<String, String> parseOptions(String[] output) {
58  		Map<String, String> options = new HashMap<>();
59  		Arrays.stream(output).forEachOrdered(s -> {
60  			int p = s.indexOf('=');
61  			if (p == -1) {
62  				return;
63  			}
64  			String key = s.substring(0, p);
65  			String value = s.substring(p + 1);
66  			options.put(key, value);
67  		});
68  		return options;
69  	}
70  
71  }