private static File getDefaultFile() { File home = FS.DETECTED.userHome(); File netrc = new File(home, ".netrc"); //$NON-NLS-1$ if (netrc.exists()) return netrc; netrc = new File(home, "_netrc"); //$NON-NLS-1$ if (netrc.exists()) return netrc; return null; }
/** * {@inheritDoc} * * @since 4.10 */ @Override protected byte[] readIncludedConfig(String relPath) throws ConfigInvalidException { final File file; if (relPath.startsWith("~/")) { //$NON-NLS-1$ file = fs.resolve(fs.userHome(), relPath.substring(2)); } else { file = fs.resolve(configFile.getParentFile(), relPath); } if (!file.exists()) { return null; } try { return IO.readFully(file); } catch (IOException ioe) { throw new ConfigInvalidException(MessageFormat .format(JGitText.get().cannotReadFile, relPath), ioe); } } }
private static String readContentAsNormalizedString(DirCacheEntry entry, ObjectReader reader) throws MissingObjectException, IOException { ObjectLoader open = reader.open(entry.getObjectId()); byte[] cachedBytes = open.getCachedBytes(); return FS.detect().normalize(RawParseUtils.decode(cachedBytes)); }
if ((options & SKIP_MISSING) != 0 && !fs.exists(f)) return; if ((options & RECURSIVE) != 0 && fs.isDirectory(f)) { final File[] items = f.listFiles(); if (items != null) { if ((options & RETRY) != 0 && fs.exists(f)) { for (int i = 1; i < 10; i++) { try {
if (hideDotFiles != HideDotFiles.FALSE && !isBare() && getDirectory().getName().startsWith(".")) //$NON-NLS-1$ getFS().setHidden(getDirectory(), true); refs.create(); objectDatabase.create(); if (getFS().supportsExecute()) { File tmp = File.createTempFile("try", "execute", getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$ getFS().setExecute(tmp, true); final boolean on = getFS().canExecute(tmp); getFS().setExecute(tmp, false); final boolean off = getFS().canExecute(tmp); FileUtils.delete(tmp); if (getFS().supportsSymlinks()) { File tmp = new File(getDirectory(), "tmplink"); //$NON-NLS-1$ try { getFS().createSymLink(tmp, "target"); //$NON-NLS-1$ symLinks = null; FileUtils.delete(tmp);
FileUtils.delete(f, FileUtils.RECURSIVE); fs.createSymLink(f, target); entry.setLength(bytes.length); entry.setLastModified(fs.lastModified(f)); return; new FileOutputStream(tmpFile), nonNullEolStreamType); if (checkoutMetadata.smudgeFilterCommand != null) { ProcessBuilder filterProcessBuilder = fs.runInShell( checkoutMetadata.smudgeFilterCommand, new String[0]); filterProcessBuilder.directory(repo.getWorkTree()); try { result = fs.execute(filterProcessBuilder, ol.openStream()); rc = result.getRc(); if (rc == 0) { if (opt.isFileMode() && fs.supportsExecute()) { if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) { if (!fs.canExecute(tmpFile)) fs.setExecute(tmpFile, true); } else { if (fs.canExecute(tmpFile)) fs.setExecute(tmpFile, false); entry.setLastModified(fs.lastModified(f));
FileUtils.delete(f, FileUtils.RECURSIVE); fs.createSymLink(f, target); entry.setLength(bytes.length); entry.setLastModified(fs.lastModified(f)); return; if (opt.isFileMode() && fs.supportsExecute()) { if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) { if (!fs.canExecute(tmpFile)) fs.setExecute(tmpFile, true); } else { if (fs.canExecute(tmpFile)) fs.setExecute(tmpFile, false); entry.setLastModified(fs.lastModified(f));
RefDirectory(FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); refsDir = fs.resolve(gitDir, R_REFS); logsDir = fs.resolve(gitDir, LOGS); logsRefsDir = fs.resolve(gitDir, LOGS + '/' + R_REFS); packedRefsFile = fs.resolve(gitDir, PACKED_REFS); looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(NO_PACKED_REFS); }
PrintStream errRedirect, String stdinArgs) throws JGitInternalException { final File hookFile = findHook(repository, hookName); if (hookFile == null) return new ProcessResult(Status.NOT_PRESENT); else runDirectory = repository.getWorkTree(); final String cmd = relativize(runDirectory.getAbsolutePath(), hookPath); ProcessBuilder hookProcess = runInShell(cmd, args); hookProcess.directory(runDirectory); Map<String, String> environment = hookProcess.environment(); return new ProcessResult(runProcess(hookProcess, outRedirect, errRedirect, stdinArgs), Status.OK); } catch (IOException e) {
/** * Check if the path may have been modified since the snapshot was saved. * * @param path * the path the snapshot describes. * @return true if the path needs to be read again. */ public boolean isModified(File path) { long currLastModified; try { currLastModified = FS.DETECTED.lastModified(path); } catch (IOException e) { currLastModified = path.lastModified(); } return isModified(currLastModified); }
@Override public boolean isModified(File path) { return FS.DETECTED.exists(path); } };
for (String p : status.getIgnoredNotInIndex()) { File f = new File(repo.getWorkTree(), p); if (fs.isFile(f) || fs.isSymLink(f)) { untrackedFiles.add(p); } else if (fs.isDirectory(f)) { untrackedDirs.add(p);
/** * Auto-detect the appropriate file system abstraction. * * @return detected file system abstraction */ public static FS detect() { return detect(null); }
CheckoutMetadata checkoutMetadata, ObjectLoader ol, FS fs, OutputStream channel) throws IOException { ProcessBuilder filterProcessBuilder = fs.runInShell( checkoutMetadata.smudgeFilterCommand, new String[0]); filterProcessBuilder.directory(repo.getWorkTree()); try { result = fs.execute(filterProcessBuilder, ol.openStream()); rc = result.getRc(); if (rc == 0) {
List<Entry> result = new ArrayList<>(); FS fs = this; boolean checkExecutable = fs.supportsExecute(); try { Files.walkFileTree(directory.toPath(),
/** * Checks whether the given hook is defined for the given repository, then * runs it with the given arguments. * <p> * The hook's standard output and error streams will be redirected to * <code>System.out</code> and <code>System.err</code> respectively. The * hook will have no stdin. * </p> * * @param repository * The repository for which a hook should be run. * @param hookName * The name of the hook to be executed. * @param args * Arguments to pass to this hook. Cannot be <code>null</code>, * but can be an empty array. * @return The ProcessResult describing this hook's execution. * @throws org.eclipse.jgit.api.errors.JGitInternalException * if we fail to run the hook somehow. Causes may include an * interrupted process or I/O errors. * @since 4.0 */ public ProcessResult runHookIfPresent(Repository repository, final String hookName, String[] args) throws JGitInternalException { return runHookIfPresent(repository, hookName, args, System.out, System.err, null); }
@Override public FileBasedConfig openSystemConfig(Config parent, FS fs) { File configFile = fs.getGitSystemConfig(); if (configFile == null) { return new FileBasedConfig(null, fs) { @Override public void load() { // empty, do not load } @Override public boolean isOutdated() { // regular class would bomb here return false; } }; } return new FileBasedConfig(parent, configFile, fs); }
/** {@inheritDoc} */ @Override public Void call() throws Exception { StoredConfig cfg = null; if (repository == null) { cfg = loadUserConfig(); } else { cfg = repository.getConfig(); } cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION, ConfigConstants.CONFIG_SECTION_LFS, ConfigConstants.CONFIG_KEY_USEJGITBUILTIN, true); cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION, ConfigConstants.CONFIG_SECTION_LFS, ConfigConstants.CONFIG_KEY_REQUIRED, true); cfg.save(); // try to run git lfs install, we really don't care if it is present // and/or works here (yet). ProcessBuilder builder = FS.DETECTED.runInShell("git", //$NON-NLS-1$ repository == null ? ARGS_USER : ARGS_LOCAL); if (repository != null) { builder.directory(repository.isBare() ? repository.getDirectory() : repository.getWorkTree()); } FS.DETECTED.runProcess(builder, null, null, (String) null); return null; }
if (repo.getFS().isFile(inTree)) { RawText rawText = getRawText(inTree); gen.push(null, rawText);