List of usage examples for org.eclipse.jgit.lib Repository getWorkTree
@NonNull public File getWorkTree() throws NoWorkTreeException
From source file:com.madgag.agit.git.Repos.java
License:Open Source License
public static File topDirectoryFor(Repository repo) { return repo.isBare() ? repo.getDirectory() : repo.getWorkTree(); }
From source file:com.madgag.agit.GitAsyncTaskTest.java
License:Open Source License
@MediumTest public void testCloneNonBareRepoFromLocalTestServer() throws Exception { Clone cloneOp = new Clone(false, integrationGitServerURIFor("small-repo.early.git"), newFolder()); Repository repo = executeAndWaitFor(cloneOp); assertThat(repo, hasGitObject("ba1f63e4430bff267d112b1e8afc1d6294db0ccc")); File readmeFile = new File(repo.getWorkTree(), "README"); assertThat(readmeFile, exists());//from www . ja v a 2 s. co m assertThat(readmeFile, ofLength(12)); }
From source file:com.madgag.agit.GitAsyncTaskTest.java
License:Open Source License
@MediumTest public void testSimpleReadOnlyCloneFromGitHub() throws Exception { Clone cloneOp = new Clone(false, new URIish("git://github.com/agittest/small-project.git"), newFolder()); Repository repo = executeAndWaitFor(cloneOp); assertThat(repo, hasGitObject("9e0b5e42b3e1c59bc83b55142a8c50dfae36b144")); assertThat(repo, not(hasGitObject("111111111111111111111111111111111111cafe"))); File readmeFile = new File(repo.getWorkTree(), "README"); assertThat(readmeFile, exists());//from w ww. j a v a2s .co m }
From source file:com.madgag.agit.RepoDeleter.java
License:Open Source License
RepoDeleter(Repository repository, Context context) { this.gitdir = repository.getDirectory(); this.topFolderToDelete = repository.isBare() ? repository.getDirectory() : repository.getWorkTree(); this.context = context; }
From source file:com.madgag.agit.Repos.java
License:Open Source License
public static String niceNameFor(Repository repo) { return niceNameFromNameDirectory(repo.isBare() ? repo.getDirectory() : repo.getWorkTree()); }
From source file:com.microsoft.gittf.client.clc.commands.CloneCommand.java
License:Open Source License
@Override public int run() throws Exception { // Parse arguments final String collection = ((FreeArgument) getArguments().getArgument("projectcollection")).getValue(); //$NON-NLS-1$ String tfsPath = ((FreeArgument) getArguments().getArgument("serverpath")).getValue(); //$NON-NLS-1$ String repositoryPath = getArguments().contains("directory") ? //$NON-NLS-1$ ((FreeArgument) getArguments().getArgument("directory")).getValue() : null; //$NON-NLS-1$ final VersionSpec versionSpec = getArguments().contains("version") ? //$NON-NLS-1$ VersionSpecUtil.parseVersionSpec(((ValueArgument) getArguments().getArgument("version")).getValue()) //$NON-NLS-1$ : LatestVersionSpec.INSTANCE; verifyVersionSpec(versionSpec);/*www . ja v a 2s . com*/ final boolean bare = getArguments().contains("bare"); //$NON-NLS-1$ final int depth = getDepthFromArguments(); final boolean mentions = getArguments().contains("mentions"); //$NON-NLS-1$ if (mentions && depth < 2) { throw new Exception(Messages.getString("Command.MentionsOnlyAvailableWithDeep")); //$NON-NLS-1$ } final boolean tag = getTagFromArguments(); final URI serverURI = URIUtil.getServerURI(collection); tfsPath = ServerPath.canonicalize(tfsPath); /* * Build repository path */ if (repositoryPath == null) { repositoryPath = ServerPath.getFileName(tfsPath); } repositoryPath = LocalPath.canonicalize(repositoryPath); final File repositoryLocation = new File(repositoryPath); File parentLocationCreated = null; if (!repositoryLocation.exists()) { parentLocationCreated = DirectoryUtil.createDirectory(repositoryLocation); if (parentLocationCreated == null) { throw new Exception(Messages.formatString("CloneCommnad.InvalidPathFormat", repositoryPath)); //$NON-NLS-1$ } } final Repository repository = RepositoryUtil.createNewRepository(repositoryPath, bare); /* * Connect to the server */ try { final TFSTeamProjectCollection connection = getConnection(serverURI, repository); Check.notNull(connection, "connection"); //$NON-NLS-1$ final WorkItemClient witClient = mentions ? connection.getWorkItemClient() : null; final CloneTask cloneTask = new CloneTask(serverURI, getVersionControlService(), tfsPath, repository, witClient); cloneTask.setBare(bare); cloneTask.setDepth(depth); cloneTask.setVersionSpec(versionSpec); cloneTask.setTag(tag); final TaskStatus cloneStatus = new CommandTaskExecutor(getProgressMonitor()).execute(cloneTask); if (!cloneStatus.isOK()) { FileHelpers.deleteDirectory(bare ? repository.getDirectory() : repository.getWorkTree()); if (parentLocationCreated != null) { FileHelpers.deleteDirectory(parentLocationCreated); } return ExitCode.FAILURE; } } finally { repository.close(); } return ExitCode.SUCCESS; }
From source file:com.microsoft.gittf.core.util.RepositoryUtil.java
License:Open Source License
public static void fixFileAttributes(final Repository repository) throws IOException { if (Platform.isCurrentPlatform(Platform.GENERIC_UNIX)) { final TreeWalk treeWalk = new NameConflictTreeWalk(repository); final Ref headReference = repository.getRef(Constants.HEAD); final RevCommit headCommit = new RevWalk(repository).parseCommit(headReference.getObjectId()); treeWalk.setRecursive(true);/*from w w w . j ava 2 s . c o m*/ treeWalk.addTree(headCommit.getTree().getId()); treeWalk.setFilter(TreeFilter.ANY_DIFF); final File workingDirectory = repository.getWorkTree(); while (treeWalk.next()) { final FileMode fileMode = treeWalk.getFileMode(0); if (FileMode.EXECUTABLE_FILE == fileMode) { final File file = new File(workingDirectory, treeWalk.getPathString()); log.debug("Executable: " + file.getAbsolutePath()); final FileSystemAttributes attr = FileSystemUtils.getInstance().getAttributes(file); attr.setExecutable(true); FileSystemUtils.getInstance().setAttributes(file, attr); } } treeWalk.reset(); } }
From source file:com.searchcode.app.jobs.repository.IndexGitHistoryJob.java
public void getRevisionChanges(Repository localRepository, Git git, GitChangeSet oldRevison, GitChangeSet newRevision) throws IOException, GitAPIException { ObjectId oldHead = localRepository.resolve(oldRevison.getRevision() + "^{tree}"); ObjectId newHead = localRepository.resolve(newRevision.getRevision() + "^{tree}"); ObjectReader reader = localRepository.newObjectReader(); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); oldTreeIter.reset(reader, oldHead);/*from w w w.j a va 2s . c o m*/ CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(reader, newHead); List<DiffEntry> entries = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call(); GitService gs = new GitService(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); for (DiffEntry entry : entries) { if ("DELETE".equals(entry.getChangeType().name())) { System.out.println("DEL " + entry.getOldPath()); String contents = gs.fetchFileRevision(localRepository.getWorkTree().toString() + "/.git", oldRevison.getRevision(), entry.getOldPath()); CodeIndexDocument cd = new CodeIndexDocument(entry.getNewPath(), "thumbor", entry.getOldPath(), entry.getOldPath(), entry.getOldPath(), "md5hash", "Java", contents.split("\\r?\\n").length, contents, "", oldRevison.getAuthor()); cd.setRevision(oldRevison.getRevision()); cd.setYearMonthDay(sdf.format(oldRevison.getExpiry())); cd.setYearMonth(cd.getYearMonthDay().substring(0, 6)); cd.setYear(cd.getYearMonthDay().substring(0, 4)); cd.setMessage(oldRevison.getMessage()); cd.setDeleted("TRUE"); Singleton.getCodeIndexer().indexTimeDocument(cd); } else { System.out.println("ADD " + entry.getNewPath()); String contents = gs.fetchFileRevision(localRepository.getWorkTree().toString() + "/.git", newRevision.getRevision(), entry.getNewPath()); CodeIndexDocument cd = new CodeIndexDocument(entry.getNewPath(), "thumbor", entry.getNewPath(), entry.getNewPath(), entry.getNewPath(), "md5hash", "Java", contents.split("\\r?\\n").length, contents, "", newRevision.getAuthor()); cd.setRevision(newRevision.getRevision()); cd.setYearMonthDay(sdf.format(oldRevison.getExpiry())); cd.setYearMonth(cd.getYearMonthDay().substring(0, 6)); cd.setYear(cd.getYearMonthDay().substring(0, 4)); cd.setMessage(newRevision.getMessage()); cd.setDeleted("FALSE"); Singleton.getCodeIndexer().indexTimeDocument(cd); } } }
From source file:com.tactfactory.harmony.utils.GitUtils.java
License:Open Source License
/** * Add a submodule to .gitmodules file.// ww w .ja va2 s . c o m * @param repositoryPath Absolute path of the repository * @param submodulePath Absolute path of the submodule repository * @param submoduleUrl Url of the submodule * @throws IOException */ public static void addSubmodule(String repositoryPath, String submodulePath, String submoduleUrl) throws IOException { // Get main repository RepositoryBuilder repoBuilder = new RepositoryBuilder(); Repository repository = repoBuilder.setWorkTree(new File(repositoryPath)) .setGitDir(new File(repositoryPath + "/.git")).readEnvironment().findGitDir().build(); // Get submodule relative path String path = TactFileUtils.absoluteToRelativePath(submodulePath, repositoryPath); path = path.substring(0, path.length() - 1); // Update .gitmodules file try { FileBasedConfig modulesConfig = new FileBasedConfig( new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES), repository.getFS()); modulesConfig.load(); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_PATH, path); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, submoduleUrl); modulesConfig.save(); } catch (ConfigInvalidException e) { ConsoleUtils.displayError(e); } repository.close(); }
From source file:edu.tum.cs.mylyn.provisioning.git.ui.GitProvisioningWizard.java
License:Open Source License
private void importProjects(Repository repository, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { List<File> files = new ArrayList<File>(); ProjectUtil.findProjectFiles(files, repository.getWorkTree(), null, monitor); Set<ProjectRecord> records = new LinkedHashSet<ProjectRecord>(); for (File file : files) { records.add(new ProjectRecord(file)); }/*from w w w. ja v a 2 s. c o m*/ ProjectUtils.createProjects(records, repository, new IWorkingSet[0], monitor); refreshWorkspace(monitor); }