List of usage examples for org.eclipse.jgit.api Git rm
public RmCommand rm()
From source file:ch.sbb.releasetrain.git.GitRepoImpl.java
License:Apache License
@Override public void addCommitPush() { try {//from w w w . java2 s. c om Git git = gitOpen(); git.add().addFilepattern(".").call(); // status Status status = git.status().call(); // rm the deleted ones if (status.getMissing().size() > 0) { for (String rm : status.getMissing()) { git.rm().addFilepattern(rm).call(); } } // commit and push if needed if (!status.hasUncommittedChanges()) { log.debug("not commiting git, because there are no changes"); return; } git.commit().setMessage("Automatic commit by releasetrain").call(); git.push().setCredentialsProvider(credentialsProvider()).call(); } catch (Exception e) { throw new GitException(e.getMessage(), e); } }
From source file:com.chungkwong.jgitgui.StageTreeItem.java
License:Open Source License
@Override public Node getContentPage() { Git git = (Git) getValue(); GridPane page = new GridPane(); ListView<String> list = new ListView<String>(); GridPane.setHgrow(list, Priority.ALWAYS); GridPane.setVgrow(list, Priority.ALWAYS); list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); try {//from w w w .j a v a 2s .c o m DirCache cache = ((Git) getValue()).getRepository().readDirCache(); for (int i = 0; i < cache.getEntryCount(); i++) list.getItems().add(cache.getEntry(i).getPathString()); } catch (Exception ex) { Logger.getLogger(StageTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } Button remove = new Button( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("REMOVE")); remove.setOnAction((e) -> { RmCommand command = git.rm().setCached(true); list.getSelectionModel().getSelectedItems().stream().forEach((path) -> { command.addFilepattern(path); }); list.getItems().removeAll(list.getSelectionModel().getSelectedItems()); try { command.call(); } catch (Exception ex) { Logger.getLogger(StageTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } }); Button blame = new Button( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("BLAME")); blame.setOnAction((e) -> { Stage dialog = new Stage(); dialog.setTitle(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("BLAME")); StringBuilder buf = new StringBuilder(); list.getSelectionModel().getSelectedItems().stream().forEach((path) -> { try { BlameResult command = git.blame().setFilePath(path).call(); RawText contents = command.getResultContents(); for (int i = 0; i < contents.size(); i++) { buf.append(command.getSourcePath(i)).append(':'); buf.append(command.getSourceLine(i)).append(':'); buf.append(command.getSourceCommit(i)).append(':'); buf.append(command.getSourceAuthor(i)).append(':'); buf.append(contents.getString(i)).append('\n'); } } catch (Exception ex) { Logger.getLogger(StageTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } }); dialog.setScene(new Scene(new TextArea(buf.toString()))); dialog.setMaximized(true); dialog.show(); }); page.addColumn(0, list, remove, blame); return page; }
From source file:com.googlesource.gerrit.plugins.uploadvalidator.TestUtils.java
License:Apache License
public static void removeFiles(Git git, Set<File> files) throws GitAPIException { RmCommand rmc = git.rm(); for (File f : files) { rmc.addFilepattern(generateFilePattern(f, git)); }//w ww . ja va 2s . c o m rmc.call(); }
From source file:com.passgit.app.PassGit.java
License:Open Source License
public void gitRemove(PathModel pathModel) { Path relativePath = rootPath.relativize(pathModel.getPath()); System.out.println(relativePath.toString()); Git git = new Git(gitRepository); try {/*from ww w .j a v a2s . c o m*/ git.rm().addFilepattern(relativePath.toString()).call(); deleteFromPathModelTreeModel(pathModel); } catch (GitAPIException ex) { Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.blizzy.documentr.access.UserStore.java
License:Open Source License
public void deleteUser(String loginName, User currentUser) throws IOException { Assert.hasLength(loginName);//from w w w . j a v a 2 s . c om Assert.notNull(currentUser); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); Git git = Git.wrap(repo.r()); git.rm().addFilepattern(loginName + USER_SUFFIX).call(); git.rm().addFilepattern(loginName + AUTHORITIES_SUFFIX).call(); PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete user " + loginName) //$NON-NLS-1$ .call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.access.UserStore.java
License:Open Source License
public void renameUser(String loginName, String newLoginName, User currentUser) throws IOException { Assert.hasLength(loginName);// w w w .ja v a 2 s . c om Assert.hasLength(newLoginName); Assert.notNull(currentUser); // check that user exists by trying to load it getUser(loginName); // check that new user does not exist by trying to load it try { getUser(newLoginName); throw new IllegalArgumentException("user already exists: " + newLoginName); //$NON-NLS-1$ } catch (UserNotFoundException e) { // okay } ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File file = new File(workingDir, loginName + USER_SUFFIX); File newFile = new File(workingDir, newLoginName + USER_SUFFIX); FileUtils.copyFile(file, newFile); file = new File(workingDir, loginName + AUTHORITIES_SUFFIX); newFile = new File(workingDir, newLoginName + AUTHORITIES_SUFFIX); FileUtils.copyFile(file, newFile); Git git = Git.wrap(repo.r()); git.rm().addFilepattern(loginName + USER_SUFFIX).call(); git.rm().addFilepattern(loginName + AUTHORITIES_SUFFIX).call(); git.add().addFilepattern(newLoginName + USER_SUFFIX).call(); git.add().addFilepattern(newLoginName + AUTHORITIES_SUFFIX).call(); PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage("rename user " + loginName + " to " + newLoginName) //$NON-NLS-1$ //$NON-NLS-2$ .call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.access.UserStore.java
License:Open Source License
public void renameRole(String roleName, String newRoleName, User currentUser) throws IOException { Assert.hasLength(roleName);//from ww w . ja v a 2s . c om Assert.hasLength(newRoleName); Assert.notNull(currentUser); // check that role exists by trying to load it getRole(roleName); // check that new role does not exist by trying to load it try { getRole(newRoleName); throw new IllegalArgumentException("role already exists: " + newRoleName); //$NON-NLS-1$ } catch (RoleNotFoundException e) { // okay } log.info("renaming role: {} -> {}", roleName, newRoleName); //$NON-NLS-1$ ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File file = new File(workingDir, roleName + ROLE_SUFFIX); File newFile = new File(workingDir, newRoleName + ROLE_SUFFIX); FileUtils.copyFile(file, newFile); Git git = Git.wrap(repo.r()); git.rm().addFilepattern(roleName + ROLE_SUFFIX).call(); git.add().addFilepattern(newRoleName + ROLE_SUFFIX).call(); List<String> users = listUsers(repo); users.add(ANONYMOUS_USER_LOGIN_NAME); for (String user : users) { List<RoleGrantedAuthority> authorities = getUserAuthorities(user, repo); Set<RoleGrantedAuthority> newAuthorities = Sets.newHashSet(); for (Iterator<RoleGrantedAuthority> iter = authorities.iterator(); iter.hasNext();) { RoleGrantedAuthority rga = iter.next(); if (rga.getRoleName().equals(roleName)) { RoleGrantedAuthority newRga = new RoleGrantedAuthority(rga.getTarget(), newRoleName); newAuthorities.add(newRga); iter.remove(); } } if (!newAuthorities.isEmpty()) { authorities.addAll(newAuthorities); saveUserAuthorities(user, Sets.newHashSet(authorities), repo, currentUser, false); } } PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage("rename role " + roleName + " to " + newRoleName) //$NON-NLS-1$ //$NON-NLS-2$ .call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.access.UserStore.java
License:Open Source License
public void deleteRole(String roleName, User currentUser) throws IOException { Assert.hasLength(roleName);/*from w w w . j a v a 2s. c o m*/ Assert.notNull(currentUser); // check that role exists by trying to load it getRole(roleName); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); Git git = Git.wrap(repo.r()); git.rm().addFilepattern(roleName + ROLE_SUFFIX).call(); // remove role from all users List<String> users = listUsers(repo); users.add(ANONYMOUS_USER_LOGIN_NAME); for (String user : users) { List<RoleGrantedAuthority> authorities = getUserAuthorities(user, repo); boolean changed = false; for (Iterator<RoleGrantedAuthority> iter = authorities.iterator(); iter.hasNext();) { RoleGrantedAuthority rga = iter.next(); if (rga.getRoleName().equals(roleName)) { iter.remove(); changed = true; } } if (changed) { saveUserAuthorities(user, Sets.newHashSet(authorities), repo, currentUser, false); } } PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete role " + roleName) //$NON-NLS-1$ .call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.page.PageStore.java
License:Open Source License
@Override public void deletePage(String projectName, String branchName, final String path, User user) throws IOException { Assert.hasLength(projectName);//from ww w.j av a2 s .c o m Assert.hasLength(branchName); Assert.hasLength(path); Assert.notNull(user); ILockedRepository repo = null; List<String> oldPagePaths; boolean deleted = false; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File pagesDir = new File(workingDir, DocumentrConstants.PAGES_DIR_NAME); File oldSubPagesDir = Util.toFile(pagesDir, path); oldPagePaths = listPagePaths(oldSubPagesDir, true); oldPagePaths = Lists.newArrayList(Lists.transform(oldPagePaths, new Function<String, String>() { @Override public String apply(String p) { return path + "/" + p; //$NON-NLS-1$ } })); oldPagePaths.add(path); Git git = Git.wrap(repo.r()); File file = Util.toFile(pagesDir, path + DocumentrConstants.PAGE_SUFFIX); if (file.isFile()) { git.rm().addFilepattern( DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.PAGE_SUFFIX) //$NON-NLS-1$ .call(); deleted = true; } file = Util.toFile(pagesDir, path + DocumentrConstants.META_SUFFIX); if (file.isFile()) { git.rm().addFilepattern( DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.META_SUFFIX) //$NON-NLS-1$ .call(); deleted = true; } file = Util.toFile(pagesDir, path); if (file.isDirectory()) { git.rm().addFilepattern(DocumentrConstants.PAGES_DIR_NAME + "/" + path) //$NON-NLS-1$ .call(); deleted = true; } File attachmentsDir = new File(workingDir, DocumentrConstants.ATTACHMENTS_DIR_NAME); file = Util.toFile(attachmentsDir, path); if (file.isDirectory()) { git.rm().addFilepattern(DocumentrConstants.ATTACHMENTS_DIR_NAME + "/" + path) //$NON-NLS-1$ .call(); deleted = true; } if (deleted) { PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete " + path) //$NON-NLS-1$ .call(); git.push().call(); PageUtil.updateProjectEditTime(projectName); } } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } if (deleted) { eventBus.post(new PagesDeletedEvent(projectName, branchName, Sets.newHashSet(oldPagePaths))); } }
From source file:de.blizzy.documentr.page.PageStore.java
License:Open Source License
@Override public void relocatePage(final String projectName, final String branchName, final String path, String newParentPagePath, User user) throws IOException { Assert.hasLength(projectName);/*from w w w.jav a 2s .com*/ Assert.hasLength(branchName); Assert.hasLength(path); Assert.hasLength(newParentPagePath); Assert.notNull(user); // check if pages exist by trying to load them getPage(projectName, branchName, path, false); getPage(projectName, branchName, newParentPagePath, false); ILockedRepository repo = null; List<String> oldPagePaths; List<String> deletedPagePaths; List<String> newPagePaths; List<PagePathChangedEvent> pagePathChangedEvents; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); String pageName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path; //$NON-NLS-1$ //$NON-NLS-2$ final String newPagePath = newParentPagePath + "/" + pageName; //$NON-NLS-1$ File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File oldSubPagesDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME), path); oldPagePaths = listPagePaths(oldSubPagesDir, true); oldPagePaths = Lists.newArrayList(Lists.transform(oldPagePaths, new Function<String, String>() { @Override public String apply(String p) { return path + "/" + p; //$NON-NLS-1$ } })); oldPagePaths.add(path); File deletedPagesSubDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME), newPagePath); deletedPagePaths = listPagePaths(deletedPagesSubDir, true); deletedPagePaths = Lists.newArrayList(Lists.transform(deletedPagePaths, new Function<String, String>() { @Override public String apply(String p) { return newPagePath + "/" + p; //$NON-NLS-1$ } })); deletedPagePaths.add(newPagePath); Git git = Git.wrap(repo.r()); AddCommand addCommand = git.add(); for (String dirName : Sets.newHashSet(DocumentrConstants.PAGES_DIR_NAME, DocumentrConstants.ATTACHMENTS_DIR_NAME)) { File dir = new File(workingDir, dirName); File newSubPagesDir = Util.toFile(dir, newPagePath); if (newSubPagesDir.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath).call(); //$NON-NLS-1$ } File newPageFile = Util.toFile(dir, newPagePath + DocumentrConstants.PAGE_SUFFIX); if (newPageFile.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$ } File newMetaFile = Util.toFile(dir, newPagePath + DocumentrConstants.META_SUFFIX); if (newMetaFile.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$ } File newParentPageDir = Util.toFile(dir, newParentPagePath); File subPagesDir = Util.toFile(dir, path); if (subPagesDir.exists()) { FileUtils.copyDirectoryToDirectory(subPagesDir, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path).call(); //$NON-NLS-1$ addCommand.addFilepattern(dirName + "/" + newParentPagePath + "/" + pageName); //$NON-NLS-1$ //$NON-NLS-2$ } File pageFile = Util.toFile(dir, path + DocumentrConstants.PAGE_SUFFIX); if (pageFile.exists()) { FileUtils.copyFileToDirectory(pageFile, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$ addCommand.addFilepattern( dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.PAGE_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$ } File metaFile = Util.toFile(dir, path + DocumentrConstants.META_SUFFIX); if (metaFile.exists()) { FileUtils.copyFileToDirectory(metaFile, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$ addCommand.addFilepattern( dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.META_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$ } } addCommand.call(); PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage("move " + path + " to " + newParentPagePath + "/" + pageName) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .call(); git.push().call(); newPagePaths = Lists.transform(oldPagePaths, new Function<String, String>() { @Override public String apply(String p) { return newPagePath + StringUtils.removeStart(p, path); } }); pagePathChangedEvents = Lists.transform(oldPagePaths, new Function<String, PagePathChangedEvent>() { @Override public PagePathChangedEvent apply(String oldPath) { String newPath = newPagePath + StringUtils.removeStart(oldPath, path); return new PagePathChangedEvent(projectName, branchName, oldPath, newPath); } }); PageUtil.updateProjectEditTime(projectName); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } Set<String> allDeletedPagePaths = Sets.newHashSet(oldPagePaths); allDeletedPagePaths.addAll(deletedPagePaths); eventBus.post(new PagesDeletedEvent(projectName, branchName, allDeletedPagePaths)); for (String newPath : newPagePaths) { eventBus.post(new PageChangedEvent(projectName, branchName, newPath)); } for (PagePathChangedEvent event : pagePathChangedEvents) { eventBus.post(event); } }