]> source.dussan.org Git - jgit.git/commitdiff
Probe filesystem and set core.filemode correctly 01/1601/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 15 Sep 2010 14:59:38 +0000 (07:59 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 15 Sep 2010 14:59:38 +0000 (07:59 -0700)
When creating a new FileRepository, probe the capability of the
local filesystem and set core.filemode based on how it reacts.

We can't just rely on FS.supportsExecute() because a POSIX system
(which usually does support execute) might be storing the repository
on a partition that doesn't have execute support (e.g. plain FAT-32).

Creating a temporary file, setting both states, checking we get
the desired results will let us set the variable correctly on
all systems.

Change-Id: I551488ea8d352d2179c7b244f474d2e3d02567a2
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java

index 66e7ebc01533268edb2179686018e75a805dc4dd..36d160ce64d5dd4f41b6a5e2a020d455ccd1206c 100644 (file)
@@ -231,10 +231,26 @@ public class FileRepository extends Repository {
                head.disableRefLog();
                head.link(Constants.R_HEADS + Constants.MASTER);
 
+               final boolean fileMode;
+               if (getFS().supportsExecute()) {
+                       File tmp = File.createTempFile("try", "execute", getDirectory());
+
+                       getFS().setExecute(tmp, true);
+                       final boolean on = getFS().canExecute(tmp);
+
+                       getFS().setExecute(tmp, false);
+                       final boolean off = getFS().canExecute(tmp);
+                       tmp.delete();
+
+                       fileMode = on && !off;
+               } else {
+                       fileMode = false;
+               }
+
                cfg.setInt(ConfigConstants.CONFIG_CORE_SECTION, null,
                                ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
                cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
-                               ConfigConstants.CONFIG_KEY_FILEMODE, true);
+                               ConfigConstants.CONFIG_KEY_FILEMODE, fileMode);
                if (bare)
                        cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
                                        ConfigConstants.CONFIG_KEY_BARE, true);