-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from c4dr01d/master
Add Console Module for Git Tool (Use Kotlin)
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import org.eclipse.jgit.api.Git | ||
import org.eclipse.jgit.api.errors.GitAPIException | ||
import org.eclipse.jgit.api.errors.JGitInternalException | ||
import org.eclipse.jgit.internal.storage.file.FileRepository | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder | ||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider | ||
import org.junit.Test | ||
import java.io.File | ||
import java.io.IOException | ||
// Modified UsernamePasswordCredentialsProvider Constructors string to apply git function is work. | ||
class GitTest { | ||
var remotePath: String? = null | ||
var localPath: String? = null | ||
var initPath: String? = null | ||
@Test | ||
@Throws(IOException::class, GitAPIException::class) | ||
fun TestClone() { | ||
val usernamePasswordCredentialsProvider = UsernamePasswordCredentialsProvider("username", "password") | ||
val cloneCommand = Git.cloneRepository() | ||
val git = cloneCommand.setURI(remotePath).setBranch("master").setDirectory(File(localPath!!)).setCredentialsProvider(usernamePasswordCredentialsProvider).call() | ||
print(git.tag()) | ||
} | ||
|
||
@Test | ||
@Throws(IOException::class) | ||
fun TestCreate() { | ||
val newRepo = FileRepositoryBuilder.create(File(initPath!! + "/.git")) | ||
newRepo.create() | ||
} | ||
|
||
@Test | ||
@Throws(IOException::class, GitAPIException::class) | ||
fun TestAdd() { | ||
val myFile = File(localPath!! + "/myfile.txt") | ||
myFile.createNewFile() | ||
val git = Git(FileRepository(localPath!! + "/.git")) | ||
git.add().addFilepattern("myFile").call() | ||
} | ||
|
||
@Test | ||
@Throws(IOException::class, GitAPIException::class, JGitInternalException::class) | ||
fun TestCommit() { | ||
val git = Git(FileRepository(localPath!! + "/.git")) | ||
git.commit().setMessage("Test Kotlin version").call() | ||
} | ||
|
||
@Test | ||
@Throws(IOException::class, GitAPIException::class) | ||
fun TestPull() { | ||
val usernamePasswordCredentialsProvider = UsernamePasswordCredentialsProvider("username", "password") | ||
val git = Git(FileRepository(localPath!! + "/.git")) | ||
git.pull().setRemoteBranchName("master").setCredentialsProvider(usernamePasswordCredentialsProvider).call() | ||
} | ||
|
||
@Test | ||
@Throws(IOException::class, GitAPIException::class, JGitInternalException::class) | ||
fun TestPush() { | ||
val usernamePasswordCredentialsProvider = UsernamePasswordCredentialsProvider("username", "password") | ||
val git = Git(FileRepository(localPath!! + "/.git")) | ||
git.push().setRemote("origin").setCredentialsProvider(usernamePasswordCredentialsProvider).call() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.util.Scanner | ||
object Main { | ||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val test = GitTest() | ||
val scanner = Scanner(System.`in`) | ||
println("Please input the Git repository url: ") | ||
test.remotePath = scanner.next() | ||
println("Please input the local path: ") | ||
test.localPath = scanner.next() | ||
println("Please input the init path: ") | ||
test.initPath = scanner.next() | ||
try { | ||
test.TestClone() | ||
test.TestCreate() | ||
test.TestAdd() | ||
test.TestCommit() | ||
test.TestPush() | ||
test.TestPull() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Git Module | ||
这是用Kotlin语言写的控制台版的Git工具,如果需要应用到QPython工程中,需要将此API测试类进行重写 | ||
## Modified By c4dr01d |