Do not add ignored files in Add command
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
This commit is contained in:
parent
09910ffa32
commit
aa86cfc339
|
@ -310,6 +310,34 @@ public void testAddFolder() throws Exception {
|
||||||
assertEquals(0, dc.getEntry("sub/b.txt").getStage());
|
assertEquals(0, dc.getEntry("sub/b.txt").getStage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAddIgnoredFile() throws Exception {
|
||||||
|
new File(db.getWorkDir(), "sub").mkdir();
|
||||||
|
File file = new File(db.getWorkDir(), "sub/a.txt");
|
||||||
|
file.createNewFile();
|
||||||
|
PrintWriter writer = new PrintWriter(file);
|
||||||
|
writer.print("content");
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
File ignoreFile = new File(db.getWorkDir(), ".gitignore");
|
||||||
|
ignoreFile.createNewFile();
|
||||||
|
writer = new PrintWriter(ignoreFile);
|
||||||
|
writer.print("sub/b.txt");
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
File file2 = new File(db.getWorkDir(), "sub/b.txt");
|
||||||
|
file2.createNewFile();
|
||||||
|
writer = new PrintWriter(file2);
|
||||||
|
writer.print("content b");
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
Git git = new Git(db);
|
||||||
|
DirCache dc = git.add().addFilepattern("sub").call();
|
||||||
|
assertEquals("sub/a.txt", dc.getEntry("sub/a.txt").getPathString());
|
||||||
|
assertNull(dc.getEntry("sub/b.txt"));
|
||||||
|
assertNotNull(dc.getEntry("sub/a.txt").getObjectId());
|
||||||
|
assertEquals(0, dc.getEntry("sub/a.txt").getStage());
|
||||||
|
}
|
||||||
|
|
||||||
private DirCacheEntry addEntryToBuilder(String path, File file,
|
private DirCacheEntry addEntryToBuilder(String path, File file,
|
||||||
ObjectWriter ow, DirCacheBuilder builder, int stage)
|
ObjectWriter ow, DirCacheBuilder builder, int stage)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
|
@ -130,12 +130,16 @@ public DirCache call() throws NoFilepatternException {
|
||||||
String path = tw.getPathString();
|
String path = tw.getPathString();
|
||||||
|
|
||||||
final File file = new File(repo.getWorkDir(), path);
|
final File file = new File(repo.getWorkDir(), path);
|
||||||
|
FileTreeIterator f = tw.getTree(1, FileTreeIterator.class);
|
||||||
|
if (tw.getTree(0, DirCacheIterator.class) == null &&
|
||||||
|
f != null && f.isEntryIgnored()) {
|
||||||
|
// file is not in index but is ignored, do nothing
|
||||||
|
}
|
||||||
// In case of an existing merge conflict the
|
// In case of an existing merge conflict the
|
||||||
// DirCacheBuildIterator iterates over all stages of
|
// DirCacheBuildIterator iterates over all stages of
|
||||||
// this path, we however want to add only one
|
// this path, we however want to add only one
|
||||||
// new DirCacheEntry per path.
|
// new DirCacheEntry per path.
|
||||||
if (!(path.equals(lastAddedFile))) {
|
else if (!(path.equals(lastAddedFile))) {
|
||||||
FileTreeIterator f = tw.getTree(1, FileTreeIterator.class);
|
|
||||||
if (f != null) { // the file exists
|
if (f != null) { // the file exists
|
||||||
DirCacheEntry entry = new DirCacheEntry(path);
|
DirCacheEntry entry = new DirCacheEntry(path);
|
||||||
entry.setLength((int)f.getEntryLength());
|
entry.setLength((int)f.getEntryLength());
|
||||||
|
|
Loading…
Reference in New Issue