diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-08-05 15:01:53 -0400 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2010-08-05 15:01:53 -0400 |
commit | ad4274abccc975bc91e0e9c10b654d40b13e2190 (patch) | |
tree | 918bdc7b48bcd5bb4d7b26d53ece06e491c088cc /org.eclipse.jgit | |
parent | bc27ac66cd3cd73fb3fa053393202680bf70fefa (diff) | |
parent | fa7d9ac5b86b6b84997cbaafe9a4e80bf76df430 (diff) | |
download | jgit-ad4274abccc975bc91e0e9c10b654d40b13e2190.tar.gz jgit-ad4274abccc975bc91e0e9c10b654d40b13e2190.zip |
Merge "Add the parameter "update" to the Add command"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java index e41ab580bb..f7d4da4d5a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java @@ -76,6 +76,8 @@ public class AddCommand extends GitCommand<DirCache> { private WorkingTreeIterator workingTreeIterator; + private boolean update = false; + /** * * @param repo @@ -158,18 +160,20 @@ public class AddCommand extends GitCommand<DirCache> { // this path, we however want to add only one // new DirCacheEntry per path. else if (!(path.equals(lastAddedFile))) { - if (f != null) { // the file exists - DirCacheEntry entry = new DirCacheEntry(path); - entry.setLength((int)f.getEntryLength()); - entry.setLastModified(f.getEntryLastModified()); - entry.setFileMode(f.getEntryFileMode()); - entry.setObjectId(ow.writeBlob(file)); - - builder.add(entry); - lastAddedFile = path; - } else { - c = tw.getTree(0, DirCacheIterator.class); - builder.add(c.getDirCacheEntry()); + if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) { + if (f != null) { // the file exists + DirCacheEntry entry = new DirCacheEntry(path); + entry.setLength((int)f.getEntryLength()); + entry.setLastModified(f.getEntryLastModified()); + entry.setFileMode(f.getEntryFileMode()); + entry.setObjectId(ow.writeBlob(file)); + + builder.add(entry); + lastAddedFile = path; + } else if (!update){ + c = tw.getTree(0, DirCacheIterator.class); + builder.add(c.getDirCacheEntry()); + } } } } @@ -186,4 +190,29 @@ public class AddCommand extends GitCommand<DirCache> { return dc; } + /** + * @param update + * If set to true, the command only matches {@code filepattern} + * against already tracked files in the index rather than the + * working tree. That means that it will never stage new files, + * but that it will stage modified new contents of tracked files + * and that it will remove files from the index if the + * corresponding files in the working tree have been removed. + * In contrast to the git command line a {@code filepattern} must + * exist also if update is set to true as there is no + * concept of a working directory here. + * + * @return {@code this} + */ + public AddCommand setUpdate(boolean update) { + this.update = update; + return this; + } + + /** + * @return is the parameter update is set + */ + public boolean isUpdate() { + return update; + } } |