You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigTest.java 2.0KB

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