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
b56c47f1
Commit
b56c47f1
authored
8 years ago
by
Florian Heck
Browse files
Options
Downloads
Patches
Plain Diff
add force checkout for cleanup
parent
948860fb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+30
-6
30 additions, 6 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
with
30 additions
and
6 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+
30
−
6
View file @
b56c47f1
...
...
@@ -78,20 +78,20 @@ public class Repository {
}
/**
* Performs a checkout of the given {@link
Commit
}.
* Performs a checkout of the given {@link
Reference
}.
*
* @param
c
* the {@link
Commit
} to checkout
* @param
ref
* the {@link
Reference
} to checkout
* @return whether the checkout was successful
* @see <a href=https://git-scm.com/docs/git-checkout>git checkout</a>
*/
public
boolean
checkout
(
Reference
c
)
{
Optional
<
ExecRes
>
checkout
=
git
.
exec
(
dir
,
"checkout"
,
c
.
getId
());
public
boolean
checkout
(
Reference
ref
)
{
Optional
<
ExecRes
>
checkout
=
git
.
exec
(
dir
,
"checkout"
,
ref
.
getId
());
Function
<
ExecRes
,
Boolean
>
toBoolean
=
res
->
{
boolean
failed
=
git
.
failed
(
res
);
if
(
failed
)
{
LOG
.
warning
(()
->
String
.
format
(
"Checkout of %s failed."
,
c
));
LOG
.
warning
(()
->
String
.
format
(
"Checkout of %s failed."
,
ref
));
}
return
!
failed
;
...
...
@@ -100,6 +100,30 @@ public class Repository {
return
checkout
.
map
(
toBoolean
).
orElse
(
false
);
}
/**
* Performs a checkout of the given {@link Reference}. All changes since last commit will be discarded.
*
* @param ref
* the {@link Reference} to checkout
* @return whether the checkout was successful
* @see <a href=https://git-scm.com/docs/git-checkout>git checkout</a>
*/
public
boolean
forceCheckout
(
Reference
ref
)
{
Optional
<
ExecRes
>
checkout
=
git
.
exec
(
dir
,
"reset"
,
"--hard"
);
Function
<
ExecRes
,
Boolean
>
toBoolean
=
res
->
{
boolean
failed
=
git
.
failed
(
res
);
if
(
failed
)
{
LOG
.
warning
(()
->
String
.
format
(
"Reset of %s failed."
,
ref
));
return
false
;
}
return
checkout
(
ref
);
};
return
checkout
.
map
(
toBoolean
).
orElse
(
false
);
}
/**
* Performs a fetch in this {@link 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