Java Code Examples for org.eclipse.jgit.lib.Constants#DOT_GIT_IGNORE

The following examples show how to use org.eclipse.jgit.lib.Constants#DOT_GIT_IGNORE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIgnoreFileWithBracket () throws Exception {
    File f = new File(workDir, "fi[le");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[[]le", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "/fi[[]le");
    GitStatus st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[[]le", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "/fi\\[le");
    // jgit seems to incorrectly handle escaped wildcards
    st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi\\[le", read(gitIgnore));
    assertEquals(0, ignores.length);
}
 
Example 2
Source File: UnignoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUnignoreFolderWithNegation () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "/sf1/sf2/folder/\n!/sf1/sf2/folder/");
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "/sf1/sf2/folder\n!/sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "!/sf1/sf2/folder/\n/sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 3
Source File: UnignoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUnignoreFileInRoot () throws Exception {
    File f = new File(workDir, "file");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "f\nf2\n/file\nf3\nf4");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("f\nf2\nf3\nf4", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 4
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIgnoreFolderNoNegationRemoval () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder\n!folder");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder\n!folder\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 5
Source File: UnignoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUnignoreFolderInSubfolder () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "/sf1/sf2/folder");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 6
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIgnoreIgnoredPartialEqualPath () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\nfile");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfile", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "sf1/sf2/file");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("sf1/sf2/file", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "sf1/*/file");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("sf1/*/file", read(gitIgnore));
    assertEquals(0, ignores.length);
}
 
Example 7
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIgnoreFolderIgnoredPartialEqualPath () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    new File(f, "file").createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\nfolder");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfolder", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "#ignoreFile\nfolder/");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfolder/", read(gitIgnore));
    assertEquals(0, ignores.length);
}
 
Example 8
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIgnoreFolderRemoveNegation () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder/\n!/sf1/sf2/folder/");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder/");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 9
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFolderIgnoredPartialEqualPath_NestedIgnoreFile () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\nfold*");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfold*", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(0, ignores.length);
}
 
Example 10
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreIgnoredPartialEqualPath_NestedIgnoreFile () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\nf*");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nf*", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(0, ignores.length);
}
 
Example 11
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFolderIgnoredEqualPath_NestedIgnoreFile () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "/sf2/folder/");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/sf2/folder/", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(0, ignores.length);
}
 
Example 12
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGitIgnoreEndsWithNewLine () throws Exception {
    File f = new File(workDir, "file");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertTrue("The .gitignore file should ends with an empty new line.",containsCRorLF(gitIgnore));
}
 
Example 13
Source File: UnignoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testUnignoreWithNegation () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "!/sf1/sf2/file");
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/file", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "/sf1/sf2/file\n!/sf1/sf2/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "!/sf1/sf2/file\n/sf1/sf2/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("file\n!/sf1/sf2/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    File gitIgnoreNested = new File(f.getParentFile(), Constants.DOT_GIT_IGNORE);
    File gitIgnoreNested2 = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnoreNested, "/file");
    write(gitIgnoreNested2, "/sf2/file");
    write(gitIgnore, "/sf1/sf2/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals("", read(gitIgnoreNested));
    assertEquals("", read(gitIgnoreNested2));
    assertEquals(Arrays.asList(gitIgnoreNested, gitIgnoreNested2, gitIgnore), Arrays.asList(ignores));
}
 
Example 14
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFileWithQuestionMark () throws Exception {
    if (isWindows()) {
        // win do not allow '?' in filename
        return;
    }
    File f = new File(workDir, "fi?le");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[?]le", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "/fi[?]le");
    GitStatus st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[?]le", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "/fi\\?le");
    // jgit seems to incorrectly handle escaped wildcards
    st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi\\?le", read(gitIgnore));
    assertEquals(0, ignores.length);
}
 
Example 15
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFileWithStarChar () throws Exception {
    if (isWindows()) {
        // win do not allow '*' in filename
        return;
    }
    File f = new File(workDir, "fi*le");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[*]le", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    write(gitIgnore, "/fi[*]le");
    GitStatus st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[*]le", read(gitIgnore));
    assertEquals(0, ignores.length);
    
    write(gitIgnore, "/fi\\*le");
    // jgit seems to incorrectly handle escaped wildcards
    st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f);
    assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC());
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi\\*le", read(gitIgnore));
    assertEquals(0, ignores.length);
}
 
Example 16
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFolderInSubfolderAppend () throws Exception {
    File f = new File(new File(new File(workDir, "subFolder"), "anotherSubfolder"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#this is ignore file\nfff\nfff2");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#this is ignore file\nfff\nfff2\n/subFolder/anotherSubfolder/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 17
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFileInRootAppend () throws Exception {
    File f = new File(workDir, "file");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#this is ignore file\n\n\nfff\nfff2");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#this is ignore file\n\n\nfff\nfff2\n/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 18
Source File: UnignoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testUnignoreFileWithBracket () throws Exception {
    File f = new File(workDir, "fi[le");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/fi[[]le", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
    
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
}
 
Example 19
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFileInSubfolder () throws Exception {
    File f = new File(new File(new File(workDir, "subFolder"), "anotherSubfolder"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/subFolder/anotherSubfolder/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
 
Example 20
Source File: IgnoreTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIgnoreFolderInRoot () throws Exception {
    File f = new File(workDir, "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}