public void initialize() throws IOException { if (!gitRepo.getDirectory().exists()) { gitRepo.create(); } else { cleanAndResetToMaster(); } }
@Signature public File getDirectory() { return getWrappedObject().getRepository().getDirectory(); }
this.remoteRepo.create(true); this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); + ConfigurationKeys.GIT_MONITOR_REPO_URI, this.remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/git-flowgraph") .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
/** * @param db * @param refname */ ReflogReaderImpl(Repository db, String refname) { logName = new File(db.getDirectory(), Constants.LOGS + '/' + refname); }
remoteRepo.create(true); Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); + ConfigurationKeys.GIT_MONITOR_REPO_URI, remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TESTDIR + "/git-flowgraph") .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
private ProcessBuilder createProcess(List<String> args) { ProcessBuilder pb = new ProcessBuilder(); pb.command(args); File directory = local != null ? local.getDirectory() : null; if (directory != null) { pb.environment().put(Constants.GIT_DIR_KEY, directory.getPath()); } return pb; }
private static String computeKey(Repository repo) { if (repo instanceof DfsRepository) { DfsRepository dfs = (DfsRepository) repo; return dfs.getDescription().getRepositoryName(); } if (repo.getDirectory() != null) { return repo.getDirectory().toURI().toString(); } throw new IllegalArgumentException(); } }
/** {@inheritDoc} */ @Override public File findHook(Repository repository, String hookName) { final File gitdir = repository.getDirectory(); if (gitdir == null) { return null; } final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS) .resolve(hookName); if (Files.isExecutable(hookPath)) return hookPath.toFile(); return null; }
/** {@inheritDoc} */ @Override @NonNull public String toString() { String desc; File directory = getDirectory(); if (directory != null) desc = directory.getPath(); else desc = getClass().getSimpleName() + "-" //$NON-NLS-1$ + System.identityHashCode(this); return "Repository[" + desc + "]"; //$NON-NLS-1$ //$NON-NLS-2$ }
@BeforeClass public void setup() throws Exception { cleanUpDir(TEST_DIR); // Create a bare repository RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED); this.remoteRepo = fileKey.open(false); this.remoteRepo.create(true); this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); // push an empty commit as a base for detecting changes this.gitForPush.commit().setMessage("First commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.config = ConfigBuilder.create() .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI, this.remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig") .addPrimitive(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog") .addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5) .build(); this.flowCatalog = new FlowCatalog(config); this.flowCatalog.startAsync().awaitRunning(); this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog); this.gitConfigMonitor.setActive(true); }
private static File createRepository() throws IOException, GitAPIException { File dir = File.createTempFile("gitinit", ".test"); if(!dir.delete()) { throw new IOException("Could not delete temporary file " + dir); } Git.init() .setDirectory(dir) .call(); try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) { System.out.println("Created a new repository at " + repository.getDirectory()); } return dir; } }
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // create the directory try (Git git = Git.init().setDirectory(localPath).call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
/** * <p> * Constructor for RebaseCommand. * </p> * * @param repo * the {@link org.eclipse.jgit.lib.Repository} */ protected RebaseCommand(Repository repo) { super(repo); walk = new RevWalk(repo); rebaseState = new RebaseState(repo.getDirectory()); }
static boolean isCached(@NonNull Repository repo) { File gitDir = repo.getDirectory(); if (gitDir == null) { return false; } FileKey key = new FileKey(gitDir, repo.getFS()); return cache.cacheMap.get(key) == repo; }
/** * @return The path to the commit edit message file relative to the * repository's work tree, or null if the repository is bare. */ private String getCommitEditMessageFilePath() { File gitDir = getRepository().getDirectory(); if (gitDir == null) { return null; } return Repository.stripWorkDir(getRepository().getWorkTree(), new File( gitDir, Constants.COMMIT_EDITMSG)); }
private static void addSubmodule(Repository mainRepo) throws GitAPIException { System.out.println("Adding submodule"); try (Git git = new Git(mainRepo)) { try (Repository subRepoInit = git.submoduleAdd(). setURI("https://github.com/github/testrepo.git"). setPath("testrepo"). call()) { if(subRepoInit.isBare()) { throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare"); } } } }
private static void addSubmodule(Repository mainRepo) throws GitAPIException { System.out.println("Adding submodule"); try (Git git = new Git(mainRepo)) { try (Repository subRepoInit = git.submoduleAdd(). setURI("https://github.com/github/testrepo.git"). setPath("testrepo"). call()) { if(subRepoInit.isBare()) { throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare"); } } } }
/** * Load the attributes node * * @return the attributes node * @throws java.io.IOException */ public AttributesNode load() throws IOException { AttributesNode r = new AttributesNode(); FS fs = repository.getFS(); File attributes = fs.resolve(repository.getDirectory(), Constants.INFO_ATTRIBUTES); FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributes); return r.getRules().isEmpty() ? null : r; }
private TemporaryBuffer doMerge(MergeResult<RawText> result) throws IOException { TemporaryBuffer.LocalFile buf = new TemporaryBuffer.LocalFile( db != null ? nonNullRepo().getDirectory() : null, inCoreLimit); try { new MergeFormatter().formatMerge(buf, result, Arrays.asList(commitNames), UTF_8); buf.close(); } catch (IOException e) { buf.destroy(); throw e; } return buf; }
@Override public Transport open(URIish uri, Repository local, String remoteName) throws NoRemoteRepositoryException { File localPath = local.isBare() ? local.getDirectory() : local.getWorkTree(); File path = local.getFS().resolve(localPath, uri.getPath()); // If the reference is to a local file, C Git behavior says // assume this is a bundle, since repositories are directories. if (path.isFile()) return new TransportBundleFile(local, uri, path); File gitDir = RepositoryCache.FileKey.resolve(path, local.getFS()); if (gitDir == null) throw new NoRemoteRepositoryException(uri, JGitText.get().notFound); return new TransportLocal(local, uri, gitDir); }