public static void delete( final JGitPathImpl path, final String sessionId, final String name, final String email, final String message, final TimeZone timeZone, final Date when, final boolean amend ) { commit( path, sessionId, name, email, message, timeZone, when, amend, new HashMap<String, File>() {{ put( path.getPath(), null ); }} ); }
public void close() throws java.io.IOException { super.close(); String sessionId = null; String name = null; String email = null; String message = null; TimeZone timeZone = null; Date when = null; if ( options != null && options.length > 0 ) { for ( final OpenOption option : options ) { if ( option instanceof CommentedOption ) { final CommentedOption op = (CommentedOption) option; sessionId = op.getSessionId(); name = op.getName(); email = op.getEmail(); message = op.getMessage(); timeZone = op.getTimeZone(); when = op.getWhen(); break; } } } commit( gPath, sessionId, name, email, message, timeZone, when, amend(), new HashMap<String, File>() {{ put( gPath.getPath(), file ); }} ); checkAmend(); } };
commit( gPath, sessionId, name, email, message, timeZone, when, amend(), new HashMap<String, File>() {{ put( gPath.getPath(), file ); if ( dotfile != null ) {
@Test public void testNewOutputStreamWithJGitOp() throws Exception { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); commit( origin, "user_branch", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/some/file/myfile.txt", tempFile( "some\n.content\nhere" ) ); }} ); final URI newRepo = URI.create( "git://outstreamwithop-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy" ); final CommentedOption op = new CommentedOption( "User Tester", "user.tester@example.com", "omg, is it the end?", formatter.parse( "31/12/2012" ) ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@outstreamwithop-test-repo/some/path/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path, op ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); final InputStream inStream = PROVIDER.newInputStream( path ); final String content = new Scanner( inStream ).useDelimiter( "\\A" ).next(); inStream.close(); assertThat( content ).isNotNull().isEqualTo( "my cool content" ); }
@Test public void testNewRepo() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git git = JGitUtil.newRepository( gitFolder, true ); assertThat( git ).isNotNull(); assertThat( branchList( git ).size() ).isEqualTo( 0 ); commit( git, "master", "name", "name@example.com", "commit", null, null, false, new HashMap<String, File>() {{ put( "file.txt", tempFile( "temp" ) ); }} ); assertThat( branchList( git ).size() ).isEqualTo( 1 ); }
@Test public void testInputStream2() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/file/myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); final URI newRepo = URI.create( "git://xinputstream-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@xinputstream-test-repo/path/to/file/myfile.txt" ) ); final InputStream inputStream = PROVIDER.newInputStream( path ); assertThat( inputStream ).isNotNull(); final String content = new Scanner( inputStream ).useDelimiter( "\\A" ).next(); inputStream.close(); assertThat( content ).isNotNull().isEqualTo( "temp\n.origin\n.content" ); }
@Test(expected = NoSuchFileException.class) public void testInputStream3() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/file/myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); final URI newRepo = URI.create( "git://xxinputstream-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@xxinputstream-test-repo/path/to" ) ); PROVIDER.newInputStream( path ); }
@Test(expected = NoSuchFileException.class) public void testInputStreamNoSuchFile() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{ put( "file.txt", tempFile( "temp.origin.content.2" ) ); }} ); final URI newRepo = URI.create( "git://inputstream-not-exists-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@inputstream-not-exists-test-repo/temp.txt" ) ); PROVIDER.newInputStream( path ); }
@Test public void testInputStream() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); final URI newRepo = URI.create( "git://inputstream-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@inputstream-test-repo/myfile.txt" ) ); final InputStream inputStream = PROVIDER.newInputStream( path ); assertThat( inputStream ).isNotNull(); final String content = new Scanner( inputStream ).useDelimiter( "\\A" ).next(); inputStream.close(); assertThat( content ).isNotNull().isEqualTo( "temp\n.origin\n.content" ); }
commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); commit( origin, "user_branch", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/some/file/myfile.txt", tempFile( "some\n.content\nhere" ) ); }} );
@Test public void testAmend() throws IOException { final File parentFolder = createTempDirectory(); System.out.println("COOL!:" + parentFolder.toString()); final File gitFolder = new File( parentFolder, "myxxxtest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "name", "name@example.com", "commit!", null, null, false, new HashMap<String, File>() {{ put( "path/to/file2.txt", tempFile( "tempwdf sdf asdf asd2222" ) ); }} ); commit( origin, "master", "name", "name@example.com", "commit!", null, null, true, new HashMap<String, File>() {{ put( "path/to/file3.txt", tempFile( "temp2x d dasdf asdf 222" ) ); }} ); final File gitClonedFolder = new File( parentFolder, "myclone.git" ); final Git git = cloneRepository( gitClonedFolder, origin.getRepository().getDirectory().toString(), true, CredentialsProvider.getDefault() ); assertThat( JGitUtil.checkPath( git, "master", "pathx/" ).getK1() ).isEqualTo( NOT_FOUND ); assertThat( JGitUtil.checkPath( git, "master", "path/to/file2.txt" ).getK1() ).isEqualTo( FILE ); assertThat( JGitUtil.checkPath( git, "master", "path/to" ).getK1() ).isEqualTo( DIRECTORY ); }
@Test public void testClone() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "user_branch", "name", "name@example.com", "commit!", null, null, false, new HashMap<String, File>() {{ put( "file2.txt", tempFile( "temp2222" ) ); }} ); commit( origin, "master", "name", "name@example.com", "commit", null, null, false, new HashMap<String, File>() {{ put( "file.txt", tempFile( "temp" ) ); }} ); commit( origin, "master", "name", "name@example.com", "commit", null, null, false, new HashMap<String, File>() {{ put( "file3.txt", tempFile( "temp3" ) ); }} ); final File gitClonedFolder = new File( parentFolder, "myclone.git" ); final Git git = cloneRepository( gitClonedFolder, origin.getRepository().getDirectory().toString(), true, CredentialsProvider.getDefault() ); assertThat( git ).isNotNull(); assertThat( branchList( git, ALL ) ).hasSize( 4 ); assertThat( branchList( git, ALL ).get( 0 ).getName() ).isEqualTo( "refs/heads/master" ); assertThat( branchList( git, ALL ).get( 1 ).getName() ).isEqualTo( "refs/heads/user_branch" ); assertThat( branchList( git, ALL ).get( 2 ).getName() ).isEqualTo( "refs/remotes/origin/master" ); assertThat( branchList( git, ALL ).get( 3 ).getName() ).isEqualTo( "refs/remotes/origin/user_branch" ); }
protected Git setupGit( final File tempDir ) throws IOException, GitAPIException { final Git git = Git.init().setBare( true ).setDirectory( tempDir ).call(); commit( git, "master", "name", "name@example.com", "cool1", null, null, false, new HashMap<String, File>() {{ put( "file1.txt", tempFile( "content" ) ); put( "file2.txt", tempFile( "content2" ) ); }} ); return git; }
@Test public void testPathResolve() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "user_branch", "name", "name@example.com", "commit!", null, null, false, new HashMap<String, File>() {{ put( "path/to/file2.txt", tempFile( "temp2222" ) ); }} ); commit( origin, "user_branch", "name", "name@example.com", "commit!", null, null, false, new HashMap<String, File>() {{ put( "path/to/file3.txt", tempFile( "temp2222" ) ); }} ); final File gitClonedFolder = new File( parentFolder, "myclone.git" ); final Git git = cloneRepository( gitClonedFolder, origin.getRepository().getDirectory().toString(), true, CredentialsProvider.getDefault() ); assertThat( JGitUtil.checkPath( git, "user_branch", "pathx/" ).getK1() ).isEqualTo( NOT_FOUND ); assertThat( JGitUtil.checkPath( git, "user_branch", "path/to/file2.txt" ).getK1() ).isEqualTo( FILE ); assertThat( JGitUtil.checkPath( git, "user_branch", "path/to" ).getK1() ).isEqualTo( DIRECTORY ); }
}} ); commit( origin.gitRepo(), "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{ put( "file.txt", tempFile( "temp" ) ); }} ); commit( origin.gitRepo(), "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{ put( "fileXXXXX.txt", tempFile( "temp" ) ); }} ); commit( origin.gitRepo(), "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{ put( "fileYYYY.txt", tempFile( "tempYYYY" ) ); }} );
final ObjectId oldHead = JGitUtil.getTreeRefObjectId( path.getFileSystem().gitRepo().getRepository(), branchName ); commit( git, branchName, name, email, message, timeZone, when, amend, content );