diff options
author | Kevin Sawicki <kevin@github.com> | 2012-01-03 15:07:02 -0800 |
---|---|---|
committer | Kevin Sawicki <kevin@github.com> | 2012-01-03 15:07:02 -0800 |
commit | c15c46e41e10283858c151a7ddf8451d1cd0cc6c (patch) | |
tree | 82cf987f52309bca742d4d09811ab331a2ac9eca /org.eclipse.jgit/src/org/eclipse | |
parent | d57c00e03696571afd92baf76cce03275b158bef (diff) | |
download | jgit-c15c46e41e10283858c151a7ddf8451d1cd0cc6c.tar.gz jgit-c15c46e41e10283858c151a7ddf8451d1cd0cc6c.zip |
Retain executable mode of existing files on Windows
Currently files in a repository marked as executable will have
that mode unset when modified and committed on systems that
do not support detection of this mode since the working tree
iterator will never report this mode for any entries.
This change updates WorkingTreeIterator to be able
to determine the target file mode to be used for the index
through consideration of the configured WorkingTreeOptions.
Bug: 364956
Change-Id: Iae496baa011b8a59d9329ec73615482b03d34a5a
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
4 files changed, 33 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java index 7e670304d9..f3e47ae011 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java @@ -171,7 +171,7 @@ public class AddCommand extends GitCommand<DirCache> { DirCacheEntry entry = new DirCacheEntry(path); if (c == null || c.getDirCacheEntry() == null || !c.getDirCacheEntry().isAssumeValid()) { - FileMode mode = f.getEntryFileMode(); + FileMode mode = f.getIndexFileMode(c); entry.setFileMode(mode); if (FileMode.GITLINK != mode) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index 14a7494ba6..a6d780e908 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -343,7 +343,7 @@ public class CommitCommand extends GitCommand<RevCommit> { long entryLength = fTree.getEntryLength(); dcEntry.setLength(entryLength); dcEntry.setLastModified(fTree.getEntryLastModified()); - dcEntry.setFileMode(fTree.getEntryFileMode()); + dcEntry.setFileMode(fTree.getIndexFileMode(dcTree)); boolean objectExists = (dcTree != null && fTree .idEqual(dcTree)) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 7387cb649c..2a42e05d39 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -751,6 +751,32 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { } /** + * Get the file mode to use for the current entry when it is to be updated + * in the index. + * + * @param indexIter + * {@link DirCacheIterator} positioned at the same entry as this + * iterator or null if no {@link DirCacheIterator} is available + * at this iterator's current entry + * @return index file mode + */ + public FileMode getIndexFileMode(final DirCacheIterator indexIter) { + final FileMode wtMode = getEntryFileMode(); + if (indexIter == null) + return wtMode; + if (getOptions().isFileMode()) + return wtMode; + final FileMode iMode = indexIter.getEntryFileMode(); + if (FileMode.REGULAR_FILE == wtMode + && FileMode.EXECUTABLE_FILE == iMode) + return iMode; + if (FileMode.EXECUTABLE_FILE == wtMode + && FileMode.REGULAR_FILE == iMode) + return iMode; + return wtMode; + } + + /** * Compares the entries content with the content in the filesystem. * Unsmudges the entry when it is detected that it is clean. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java index 630d00b376..dafb3a1517 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.treewalk; import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; @@ -60,8 +61,10 @@ public class WorkingTreeOptions { private final AutoCRLF autoCRLF; private WorkingTreeOptions(final Config rc) { - fileMode = rc.getBoolean("core", "filemode", true); - autoCRLF = rc.getEnum("core", null, "autocrlf", AutoCRLF.FALSE); + fileMode = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, + ConfigConstants.CONFIG_KEY_FILEMODE, true); + autoCRLF = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); } /** @return true if the execute bit on working files should be trusted. */ |