List of usage examples for org.eclipse.jgit.api Git rm
public RmCommand rm()
From source file:de.blizzy.documentr.page.PageStore.java
License:Open Source License
@Override public void deleteAttachment(String projectName, String branchName, String pagePath, String name, User user) throws IOException { Assert.hasLength(projectName);/*from w w w . j a va 2s. c om*/ Assert.hasLength(branchName); Assert.hasLength(pagePath); Assert.hasLength(name); Assert.notNull(user); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); Git git = Git.wrap(repo.r()); File attachmentsDir = new File(workingDir, DocumentrConstants.ATTACHMENTS_DIR_NAME); boolean deleted = false; File file = Util.toFile(attachmentsDir, pagePath + "/" + name + DocumentrConstants.PAGE_SUFFIX); //$NON-NLS-1$ if (file.isFile()) { FileUtils.forceDelete(file); git.rm().addFilepattern(DocumentrConstants.ATTACHMENTS_DIR_NAME + "/" + //$NON-NLS-1$ pagePath + "/" + name + DocumentrConstants.PAGE_SUFFIX) //$NON-NLS-1$ .call(); deleted = true; } file = Util.toFile(attachmentsDir, pagePath + "/" + name + DocumentrConstants.META_SUFFIX); //$NON-NLS-1$ if (file.isFile()) { FileUtils.forceDelete(file); git.rm().addFilepattern(DocumentrConstants.ATTACHMENTS_DIR_NAME + "/" + //$NON-NLS-1$ pagePath + "/" + name + DocumentrConstants.META_SUFFIX) //$NON-NLS-1$ .call(); deleted = true; } if (deleted) { PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete " + pagePath + "/" + name) //$NON-NLS-1$ //$NON-NLS-2$ .call(); git.push().call(); PageUtil.updateProjectEditTime(projectName); } } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.subscription.SubscriptionStore.java
License:Open Source License
public void unsubscribe(String projectName, String branchName, String path, User user) throws IOException { ILockedRepository repo = null;/* www. j a va 2 s .c o m*/ try { repo = getOrCreateRepository(user); String json = BlobUtils.getHeadContent(repo.r(), user.getLoginName() + SUBSCRIPTIONS_SUFFIX); if (StringUtils.isNotBlank(json)) { Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); List<Page> pagesList = gson.fromJson(json, new TypeToken<List<Page>>() { }.getType()); Set<Page> pages = Sets.newHashSet(pagesList); Page page = new Page(projectName, branchName, path); if (pages.remove(page)) { Git git = Git.wrap(repo.r()); if (!pages.isEmpty()) { json = gson.toJson(pages); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File file = new File(workingDir, user.getLoginName() + SUBSCRIPTIONS_SUFFIX); FileUtils.writeStringToFile(file, json, Charsets.UTF_8); git.add().addFilepattern(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call(); } else { git.rm().addFilepattern(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call(); } PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call(); } } } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:eu.mihosoft.vrl.io.VersionedFile.java
License:Open Source License
/** * Commit file changes. IF flushing for commits is enabled changes will be * flushed.//from www . j a v a 2 s. com * * @param message commit message * @return this file * @throws IOException * @throws IllegalStateException if this file is currently not open */ public VersionedFile commit(String message) throws IOException { // file has to be opened if (!isOpened()) { throw new IllegalStateException("File\"" + getFile().getPath() + "\" not opened!"); } Git git = null; try { // this should NEVER happen if (hasConflicts()) { throw new IllegalStateException("File \"" + getFile().getPath() + "\" has conflicts!"); } // ensures that message is not null if (message == null || message.isEmpty()) { message = "no message"; } System.out.print(">> commit version "); // open the git repository git = Git.open(tmpFolder); // retrieve the current git status Status status = git.status().call(); // rm command to tell git to remove files RmCommand rm = git.rm(); boolean needsRM = false; // checks whether rm is necessary and adds relevant paths for (String removedFile : status.getMissing()) { rm.addFilepattern(removedFile); needsRM = true; } // calls the rm command if necessary if (needsRM) { rm.call(); } // adds all remaining files git.add().addFilepattern(".").call(); // perform the commit git.commit().setMessage(message).setAuthor(System.getProperty("user.name"), "?").call(); commits = null; // updates the current version number currentVersion = getNumberOfVersions() - 1; System.out.println(currentVersion + ": "); System.out.println(">>> commit-id (SHA-1): " + getVersions().get(currentVersion).getName()); if (isFlushCommits()) { flush(); } closeGit(git); return this; } catch (NoFilepatternException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (NoHeadException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (NoMessageException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (UnmergedPathException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (ConcurrentRefUpdateException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (JGitInternalException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (WrongRepositoryStateException ex) { closeGit(git); throw new IOException("Git exception", ex); } catch (IOException ex) { closeGit(git); throw new IOException("Git exception", ex); } }
From source file:gov.va.isaac.sync.git.SyncServiceGIT.java
License:Apache License
/** * @see gov.va.isaac.interfaces.sync.ProfileSyncI#removeFiles(java.io.File, java.util.Set) *///from w ww . j av a 2 s .c om @Override public void removeFiles(String... files) throws IllegalArgumentException, IOException { try { log.info("Remove Files called {}", Arrays.toString(files)); Git git = getGit(); if (files.length == 0) { log.debug("No files to remove"); } else { RmCommand rm = git.rm(); for (String file : files) { rm.addFilepattern(file); } rm.call(); } log.info("removeFiles Complete. Current status: " + statusToString(git.status().call())); } catch (GitAPIException e) { log.error("Unexpected", e); throw new IOException("Internal error", e); } }
From source file:io.fabric8.forge.rest.git.RepositoryResource.java
License:Apache License
protected CommitInfo doRemove(Git git, List<String> paths) throws Exception { if (paths != null && paths.size() > 0) { int count = 0; for (String path : paths) { File file = getRelativeFile(path); if (file.exists()) { count++;// ww w . j a v a2 s. com Files.recursiveDelete(file); String filePattern = getFilePattern(path); git.rm().addFilepattern(filePattern).call(); } } if (count > 0) { CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(message); return createCommitInfo(commitThenPush(git, commit)); } } return null; }
From source file:io.fabric8.forge.rest.git.RepositoryResource.java
License:Apache License
protected CommitInfo doRemove(Git git, String path) throws Exception { File file = getRelativeFile(path); if (file.exists()) { Files.recursiveDelete(file); String filePattern = getFilePattern(path); git.rm().addFilepattern(filePattern).call(); CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(message); return createCommitInfo(commitThenPush(git, commit)); } else {//from w ww . ja v a2 s . co m return null; } }
From source file:io.fabric8.git.internal.GitDataStore.java
License:Apache License
protected void doRecursiveDeleteAndRemove(Git git, File file) throws IOException, GitAPIException { assertValid();//from ww w . j av a 2 s .co m File rootDir = GitHelpers.getRootGitDirectory(git); String relativePath = getFilePattern(rootDir, file); if (file.exists() && !relativePath.equals(".git")) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { doRecursiveDeleteAndRemove(git, child); } } } file.delete(); git.rm().addFilepattern(relativePath).call(); } }
From source file:io.fabric8.git.internal.GitDataStoreImpl.java
License:Apache License
private void recursiveDeleteAndRemove(Git git, File file) throws IOException, GitAPIException { File rootDir = GitHelpers.getRootGitDirectory(git); String relativePath = getFilePattern(rootDir, file); if (file.exists() && !relativePath.equals(".git")) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { recursiveDeleteAndRemove(git, child); }// w w w .j a v a2 s .co m } } file.delete(); git.rm().addFilepattern(relativePath).call(); } }
From source file:io.fabric8.git.zkbridge.Bridge.java
License:Apache License
private static void syncVersionFromZkToGit(Git git, CuratorFramework curator, String zkNode) throws Exception { // Version metadata Properties versionProps = loadProps(curator, zkNode); versionProps.save(new File(getGitProfilesDirectory(git), METADATA)); git.add().addFilepattern(METADATA).call(); // Profiles/* ww w.j a v a 2 s . c om*/ List<String> gitProfiles = list(getGitProfilesDirectory(git)); gitProfiles.remove(".git"); gitProfiles.remove(METADATA); gitProfiles.remove(CONTAINERS_PROPERTIES); List<String> zkProfiles = getChildren(curator, zkNode + "/profiles"); for (String profile : zkProfiles) { File profileDir = new File(getGitProfilesDirectory(git), profile); profileDir.mkdirs(); // Profile metadata Properties profileProps = loadProps(curator, zkNode + "/profiles/" + profile); profileProps.save(new File(getGitProfilesDirectory(git), profile + "/" + METADATA)); git.add().addFilepattern(profile + "/" + METADATA).call(); // Configs List<String> gitConfigs = list(profileDir); gitConfigs.remove(METADATA); List<String> zkConfigs = getChildren(curator, zkNode + "/profiles/" + profile); for (String file : zkConfigs) { byte[] data = curator.getData().forPath(zkNode + "/profiles/" + profile + "/" + file); Files.writeToFile(new File(getGitProfilesDirectory(git), profile + "/" + file), data); gitConfigs.remove(file); git.add().addFilepattern(profile + "/" + file).call(); } for (String file : gitConfigs) { new File(profileDir, file).delete(); git.rm().addFilepattern(profile + "/" + file).call(); } gitProfiles.remove(profile); } for (String profile : gitProfiles) { delete(new File(getGitProfilesDirectory(git), profile)); git.rm().addFilepattern(profile).call(); } // Containers Properties containerProps = new Properties(); for (String container : getChildren(curator, zkNode + "/containers")) { String str = getStringData(curator, zkNode + "/containers/" + container); if (str != null) { containerProps.setProperty(container, str); } } containerProps.save(new File(getGitProfilesDirectory(git), CONTAINERS_PROPERTIES)); git.add().addFilepattern(CONTAINERS_PROPERTIES).call(); }
From source file:io.fabric8.openshift.agent.DeploymentUpdater.java
License:Apache License
protected void deleteFiles(Git git, File baseDir, String path, List<String> fileNames) throws GitAPIException { if (path != null) { for (String fileName : fileNames) { File file = new File(baseDir, path + "/" + fileName); if (file.exists()) { LOG.debug("Removing " + file + " for container " + container.getId()); git.rm().addFilepattern(path + "/" + fileName).call(); file.delete();/*from w ww . ja v a2 s. co m*/ } } } }