]> source.dussan.org Git - jgit.git/commitdiff
FS: Add a method to discover the system-wide config file 45/48145/6
authorSebastian Schuberth <sschuberth@gmail.com>
Tue, 19 May 2015 08:49:44 +0000 (10:49 +0200)
committerSebastian Schuberth <sschuberth@gmail.com>
Fri, 22 May 2015 07:37:26 +0000 (09:37 +0200)
Change-Id: I969e26a5ab5f8ca3ab29024f405c1e34afdba493
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

index 4a85e560e8da25fba8c79b89beeb145792addfa4..f61606e48e809fbee335c580a257385b52e9a64e 100644 (file)
@@ -53,10 +53,12 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.text.MessageFormat;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
@@ -536,6 +538,31 @@ public abstract class FS {
         */
        protected abstract File discoverGitExe();
 
+       /**
+        * @return the path to the system-wide Git configuration file.
+        * @since 4.0
+        */
+       protected File discoverGitSystemConfig() {
+               File gitExe = discoverGitExe();
+               if (gitExe == null) {
+                       return null;
+               }
+
+               // Trick Git into printing the path to the config file by using "echo"
+               // as the editor.
+               Map<String, String> env = new HashMap<>();
+               env.put("GIT_EDITOR", "echo"); //$NON-NLS-1$ //$NON-NLS-2$
+
+               String w = readPipe(gitExe.getParentFile(),
+                               new String[] { "git", "config", "--system", "--edit" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                               Charset.defaultCharset().name(), env);
+               if (StringUtils.isEmptyOrNull(w)) {
+                       return null;
+               }
+
+               return new File(w);
+       }
+
        /** @return the $prefix directory C Git would use. */
        protected File discoverGitPrefix() {
                return resolveGrandparentFile(discoverGitExe());