|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> |
|
|
|
* Copyright (C) 2010, 2012 Chris Aniszczyk <caniszczyk@gmail.com> |
|
|
|
* and other copyright owners as documented in the project's IP log. |
|
|
|
* and other copyright owners as documented in the project's IP log. |
|
|
|
* |
|
|
|
* |
|
|
|
* This program and the accompanying materials are made available |
|
|
|
* This program and the accompanying materials are made available |
|
|
@ -61,10 +61,27 @@ import org.eclipse.jgit.treewalk.TreeWalk; |
|
|
|
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; |
|
|
|
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A class used to execute a {@code Rm} command. It has setters for all |
|
|
|
* Remove files from the index and working directory (or optionally only from |
|
|
|
* supported options and arguments of this command and a {@link #call()} method |
|
|
|
* the index). |
|
|
|
* to finally execute the command. Each instance of this class should only be |
|
|
|
* <p> |
|
|
|
* used for one invocation of the command (means: one call to {@link #call()}) |
|
|
|
* It has setters for all supported options and arguments of this command and a |
|
|
|
|
|
|
|
* {@link #call()} method to finally execute the command. Each instance of this |
|
|
|
|
|
|
|
* class should only be used for one invocation of the command (means: one call |
|
|
|
|
|
|
|
* to {@link #call()}). |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* Examples (<code>git</code> is a {@link Git} instance): |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* Remove file "test.txt" from both index and working directory: |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <pre> |
|
|
|
|
|
|
|
* git.rm().addFilepattern("test.txt").call(); |
|
|
|
|
|
|
|
* </pre> |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* Remove file "new.txt" from the index (but not from the working directory): |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <pre> |
|
|
|
|
|
|
|
* git.rm().setCached(true).addFilepattern("new.txt").call(); |
|
|
|
|
|
|
|
* </pre> |
|
|
|
* |
|
|
|
* |
|
|
|
* @see <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html" |
|
|
|
* @see <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html" |
|
|
|
* >Git documentation about Rm</a> |
|
|
|
* >Git documentation about Rm</a> |
|
|
@ -73,6 +90,9 @@ public class RmCommand extends GitCommand<DirCache> { |
|
|
|
|
|
|
|
|
|
|
|
private Collection<String> filepatterns; |
|
|
|
private Collection<String> filepatterns; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Only remove files from index, not from working directory */ |
|
|
|
|
|
|
|
private boolean cached = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* @param repo |
|
|
|
* @param repo |
|
|
@ -93,6 +113,21 @@ public class RmCommand extends GitCommand<DirCache> { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Only remove the specified files from the index. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param cached |
|
|
|
|
|
|
|
* true if files should only be removed from index, false if |
|
|
|
|
|
|
|
* files should also be deleted from the working directory |
|
|
|
|
|
|
|
* @return {@code this} |
|
|
|
|
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public RmCommand setCached(boolean cached) { |
|
|
|
|
|
|
|
checkCallable(); |
|
|
|
|
|
|
|
this.cached = cached; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Executes the {@code Rm} command. Each instance of this class should only |
|
|
|
* Executes the {@code Rm} command. Each instance of this class should only |
|
|
|
* be used for one invocation of the command. Don't call this method twice |
|
|
|
* be used for one invocation of the command. Don't call this method twice |
|
|
@ -118,15 +153,17 @@ public class RmCommand extends GitCommand<DirCache> { |
|
|
|
tw.addTree(new DirCacheBuildIterator(builder)); |
|
|
|
tw.addTree(new DirCacheBuildIterator(builder)); |
|
|
|
|
|
|
|
|
|
|
|
while (tw.next()) { |
|
|
|
while (tw.next()) { |
|
|
|
final File path = new File(repo.getWorkTree(), |
|
|
|
if (!cached) { |
|
|
|
tw.getPathString()); |
|
|
|
|
|
|
|
final FileMode mode = tw.getFileMode(0); |
|
|
|
final FileMode mode = tw.getFileMode(0); |
|
|
|
if (mode.getObjectType() == Constants.OBJ_BLOB) { |
|
|
|
if (mode.getObjectType() == Constants.OBJ_BLOB) { |
|
|
|
|
|
|
|
final File path = new File(repo.getWorkTree(), |
|
|
|
|
|
|
|
tw.getPathString()); |
|
|
|
// Deleting a blob is simply a matter of removing
|
|
|
|
// Deleting a blob is simply a matter of removing
|
|
|
|
// the file or symlink named by the tree entry.
|
|
|
|
// the file or symlink named by the tree entry.
|
|
|
|
delete(path); |
|
|
|
delete(path); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
builder.commit(); |
|
|
|
builder.commit(); |
|
|
|
setCallable(false); |
|
|
|
setCallable(false); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|