Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitWrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Georg Seibt
GitWrapper
Commits
51c6aa86
Commit
51c6aa86
authored
8 years ago
by
Georg Seibt
Browse files
Options
Downloads
Patches
Plain Diff
doc
parent
7ae542a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java
+32
-3
32 additions, 3 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+3
-3
3 additions, 3 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
with
35 additions
and
6 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Git.java
→
src/de/uni_passau/fim/seibt/gitwrapper/repo/Git
Wrapper
.java
+
32
−
3
View file @
51c6aa86
...
@@ -12,12 +12,15 @@ import java.util.regex.Pattern;
...
@@ -12,12 +12,15 @@ import java.util.regex.Pattern;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
public
class
Git
{
/**
* A wrapper for executing git commands on the command line.
*/
public
class
GitWrapper
{
public
static
final
int
EXIT_SUCCESS
=
0
;
public
static
final
int
EXIT_SUCCESS
=
0
;
public
static
final
int
EXIT_FAIL
=
1
;
public
static
final
int
EXIT_FAIL
=
1
;
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
Git
.
class
.
getCanonicalName
());
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
Git
Wrapper
.
class
.
getCanonicalName
());
private
static
final
Pattern
CLONING_INTO
=
Pattern
.
compile
(
"Cloning into '(.*)'\\.\\.\\."
);
private
static
final
Pattern
CLONING_INTO
=
Pattern
.
compile
(
"Cloning into '(.*)'\\.\\.\\."
);
private
static
final
Pattern
ALREADY_EXISTS
=
Pattern
.
compile
(
"fatal: destination path '(.*)' already exists and is not an empty directory\\."
);
private
static
final
Pattern
ALREADY_EXISTS
=
Pattern
.
compile
(
"fatal: destination path '(.*)' already exists and is not an empty directory\\."
);
...
@@ -29,10 +32,26 @@ public class Git {
...
@@ -29,10 +32,26 @@ public class Git {
private
String
git
;
private
String
git
;
public
Git
(
String
git
)
{
/**
* Constructs a new {@link GitWrapper}
*
* @param git the git command, e.g. '/usr/bin/git' or just 'git'
*/
public
GitWrapper
(
String
git
)
{
this
.
git
=
git
;
this
.
git
=
git
;
}
}
/**
* Attempts to clone the git repository at the given <code>url</code> into a directory under <code>parentDir</code>.
* If <code>parentDir</code> already contains a git repository with the name that would be produced when cloning
* <code>url</code> it is assumed to be a clone of <code>url</code> and returned as a {@link Repository}.
*
* @param parentDir
* the directory in which to place the clone of <code>url</code>
* @param url
* the git repository to clone
* @return the resulting {@link Repository} or an empty {@link Optional} if there is an error
*/
public
Optional
<
Repository
>
clone
(
File
parentDir
,
String
url
)
{
public
Optional
<
Repository
>
clone
(
File
parentDir
,
String
url
)
{
LOG
.
fine
(()
->
String
.
format
(
"Cloning '%s'."
,
url
));
LOG
.
fine
(()
->
String
.
format
(
"Cloning '%s'."
,
url
));
...
@@ -100,6 +119,16 @@ public class Git {
...
@@ -100,6 +119,16 @@ public class Git {
return
status
.
map
(
res
->
res
.
code
==
EXIT_SUCCESS
).
orElse
(
false
);
return
status
.
map
(
res
->
res
.
code
==
EXIT_SUCCESS
).
orElse
(
false
);
}
}
/**
* Executes 'git <parameters>' and returns the exit code and the output of the command. If there is an
* exception executing the command an empty {@link Optional} will be returned.
*
* @param workingDirectory
* the working directory for the command execution
* @param parameters
* the git parameters
* @return the result of the execution
*/
public
Optional
<
ExecRes
>
exec
(
File
workingDirectory
,
String
...
parameters
)
{
public
Optional
<
ExecRes
>
exec
(
File
workingDirectory
,
String
...
parameters
)
{
ProcessBuilder
b
=
new
ProcessBuilder
();
ProcessBuilder
b
=
new
ProcessBuilder
();
String
[]
cmdArray
=
new
String
[
parameters
.
length
+
1
];
String
[]
cmdArray
=
new
String
[
parameters
.
length
+
1
];
...
...
This diff is collapsed.
Click to expand it.
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+
3
−
3
View file @
51c6aa86
...
@@ -4,13 +4,13 @@ import java.io.File;
...
@@ -4,13 +4,13 @@ import java.io.File;
public
class
Repository
{
public
class
Repository
{
private
Git
git
;
private
Git
Wrapper
gitWrapper
;
private
String
url
;
private
String
url
;
private
File
dir
;
private
File
dir
;
Repository
(
Git
git
,
String
url
,
File
dir
)
{
Repository
(
Git
Wrapper
gitWrapper
,
String
url
,
File
dir
)
{
this
.
git
=
git
;
this
.
git
Wrapper
=
gitWrapper
;
this
.
url
=
url
;
this
.
url
=
url
;
this
.
dir
=
dir
;
this
.
dir
=
dir
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment