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
3dc0f206
Commit
3dc0f206
authored
8 years ago
by
Georg Seibt
Browse files
Options
Downloads
Patches
Plain Diff
optional fetch
parent
698c3f92
No related branches found
No related tags found
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
+11
-3
11 additions, 3 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+23
-2
23 additions, 2 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
with
34 additions
and
5 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java
+
11
−
3
View file @
3dc0f206
...
@@ -56,9 +56,11 @@ public class GitWrapper extends ToolWrapper {
...
@@ -56,9 +56,11 @@ public class GitWrapper extends ToolWrapper {
* the directory in which to place the clone of <code>url</code>
* the directory in which to place the clone of <code>url</code>
* @param url
* @param url
* the git repository to clone
* the git repository to clone
* @param fetch
* whether to perform a fetch of the {@link Repository} if a clone of it was already found on disk
* @return the resulting {@link Repository} or an empty {@link Optional} if there is an error
* @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
,
boolean
fetch
)
{
LOG
.
fine
(()
->
String
.
format
(
"Cloning '%s'."
,
url
));
LOG
.
fine
(()
->
String
.
format
(
"Cloning '%s'."
,
url
));
Optional
<
ExecRes
>
res
=
exec
(
parentDir
,
"clone"
,
url
);
Optional
<
ExecRes
>
res
=
exec
(
parentDir
,
"clone"
,
url
);
...
@@ -90,6 +92,7 @@ public class GitWrapper extends ToolWrapper {
...
@@ -90,6 +92,7 @@ public class GitWrapper extends ToolWrapper {
if
(
execRes
.
exitCode
==
EXIT_SUCCESS
)
{
if
(
execRes
.
exitCode
==
EXIT_SUCCESS
)
{
LOG
.
fine
(()
->
String
.
format
(
"Cloned '%s' into '%s'."
,
url
,
repoPath
));
LOG
.
fine
(()
->
String
.
format
(
"Cloned '%s' into '%s'."
,
url
,
repoPath
));
return
new
Repository
(
this
,
url
,
repoDir
);
}
else
{
}
else
{
LOG
.
fine
(()
->
String
.
format
(
"Found '%s' which would be produced for '%s'"
,
repoPath
,
url
));
LOG
.
fine
(()
->
String
.
format
(
"Found '%s' which would be produced for '%s'"
,
repoPath
,
url
));
...
@@ -99,9 +102,14 @@ public class GitWrapper extends ToolWrapper {
...
@@ -99,9 +102,14 @@ public class GitWrapper extends ToolWrapper {
}
}
LOG
.
fine
(()
->
String
.
format
(
"'%s' is a git repository. Assuming it is a clone of '%s'."
,
repoPath
,
url
));
LOG
.
fine
(()
->
String
.
format
(
"'%s' is a git repository. Assuming it is a clone of '%s'."
,
repoPath
,
url
));
}
Repository
repo
=
new
Repository
(
this
,
url
,
repoDir
);
if
(
fetch
&&
!
repo
.
fetch
())
{
LOG
.
warning
(
"Could not fetch "
+
repo
+
". It may be out of date."
);
}
return
new
Repository
(
this
,
url
,
repoDir
);
return
repo
;
}
};
};
return
res
.
map
(
toRepo
);
return
res
.
map
(
toRepo
);
...
...
This diff is collapsed.
Click to expand it.
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+
23
−
2
View file @
3dc0f206
...
@@ -63,7 +63,7 @@ public class Repository {
...
@@ -63,7 +63,7 @@ public class Repository {
* @param c
* @param c
* the {@link Commit} to checkout
* the {@link Commit} to checkout
* @return whether the checkout was successful
* @return whether the checkout was successful
* @see <a href=https://git-scm.com/docs/git-checkout>git
-
checkout</a>
* @see <a href=https://git-scm.com/docs/git-checkout>git
checkout</a>
*/
*/
public
boolean
checkout
(
Commit
c
)
{
public
boolean
checkout
(
Commit
c
)
{
...
@@ -80,12 +80,33 @@ public class Repository {
...
@@ -80,12 +80,33 @@ public class Repository {
LOG
.
warning
(()
->
String
.
format
(
"Checkout of %s failed."
,
c
));
LOG
.
warning
(()
->
String
.
format
(
"Checkout of %s failed."
,
c
));
}
}
return
failed
;
return
!
failed
;
};
};
return
checkout
.
map
(
toBoolean
).
orElse
(
false
);
return
checkout
.
map
(
toBoolean
).
orElse
(
false
);
}
}
/**
* Performs a fetch in this {@link Repository}.
*
* @return whether the fetch was successful
* @see <a href=https://git-scm.com/docs/git-fetch>git fetch</a>
*/
public
boolean
fetch
()
{
Optional
<
ExecRes
>
fetch
=
git
.
exec
(
dir
,
"fetch"
,
"--all"
,
"--tags"
);
//TODO add "--prune"?
Function
<
ExecRes
,
Boolean
>
toBoolean
=
res
->
{
boolean
failed
=
git
.
failed
(
res
);
if
(
failed
)
{
LOG
.
warning
(()
->
String
.
format
(
"Fetch of %s failed."
,
this
));
}
return
!
failed
;
};
return
fetch
.
map
(
toBoolean
).
orElse
(
false
);
}
/**
/**
* Returns the merge commits in this repository.
* Returns the merge commits in this repository.
*
*
...
...
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