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
9e736619
Commit
9e736619
authored
8 years ago
by
Florian Heck
Browse files
Options
Downloads
Patches
Plain Diff
added status bean and method for parsing status
parent
1e96e56f
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/Repository.java
+14
-0
14 additions, 0 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java
+67
-0
67 additions, 0 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java
with
81 additions
and
0 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+
14
−
0
View file @
9e736619
...
@@ -452,6 +452,20 @@ public class Repository {
...
@@ -452,6 +452,20 @@ public class Repository {
return
Optional
.
of
(
conflicts
);
return
Optional
.
of
(
conflicts
);
}
}
public
Optional
<
Status
>
getStatus
()
{
Optional
<
ExecRes
>
output
=
git
.
exec
(
dir
,
"status"
,
"-z"
);
Function
<
ExecRes
,
Status
>
toStatus
=
execRes
->
{
if
(
git
.
failed
(
execRes
))
{
LOG
.
warning
(()
->
String
.
format
(
"Failed to get status information for repo %s"
,
this
));
return
null
;
}
return
Status
.
parseStatus
(
this
,
execRes
.
stdOut
+
"\0"
);
};
return
output
.
map
(
toStatus
);
}
/**
/**
* Returns the {@link GitWrapper} used by this {@link Repository}.
* Returns the {@link GitWrapper} used by this {@link Repository}.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java
0 → 100644
+
67
−
0
View file @
9e736619
package
de.uni_passau.fim.seibt.gitwrapper.repo
;
import
java.io.File
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
Status
{
private
static
final
Pattern
STATUS_ENTRY
=
Pattern
.
compile
(
"(.?.) (?:.*? )?(.*?)\0"
);
public
final
String
head
;
public
final
Map
<
File
,
String
>
changed
;
public
final
Map
<
File
,
String
>
unmerged
;
private
Status
(
String
head
,
Map
<
File
,
String
>
changed
,
Map
<
File
,
String
>
unmerged
)
{
this
.
head
=
head
;
this
.
changed
=
Collections
.
unmodifiableMap
(
changed
);
this
.
unmerged
=
Collections
.
unmodifiableMap
(
unmerged
);
}
public
boolean
isClean
()
{
return
changed
.
isEmpty
()
&&
unmerged
.
isEmpty
();
}
public
boolean
hasConflicts
()
{
return
!
unmerged
.
isEmpty
();
}
@Override
public
String
toString
()
{
String
out
=
""
;
if
(
isClean
())
{
out
=
"Clean working directory on commit "
+
head
+
"\n"
;
}
else
{
if
(!
unmerged
.
isEmpty
())
{
out
=
"Unmerged files:"
;
out
+=
unmerged
.
keySet
().
stream
().
map
(
File:
:
getPath
).
reduce
(
""
,
(
list
,
file
)
->
String
.
join
(
"\n"
,
list
,
file
));
out
+=
"\n"
;
}
if
(!
changed
.
isEmpty
())
{
out
+=
"Changed files:"
;
out
+=
changed
.
keySet
().
stream
().
map
(
File:
:
getPath
).
reduce
(
""
,
(
list
,
file
)
->
String
.
join
(
"\n"
,
list
,
file
));
out
+=
"\n"
;
}
}
return
out
;
}
static
Status
parseStatus
(
Repository
repo
,
String
gitOutput
)
{
Map
<
File
,
String
>
changed
=
new
HashMap
<>();
Map
<
File
,
String
>
unmerged
=
new
HashMap
<>();
Matcher
matcher
=
STATUS_ENTRY
.
matcher
(
gitOutput
);
while
(
matcher
.
find
())
{
// used new path, if file was moved
File
file
=
new
File
(
matcher
.
group
(
2
));
String
code
=
matcher
.
group
(
1
).
toUpperCase
();
if
(
code
.
contains
(
"U"
))
{
unmerged
.
put
(
file
,
code
);
}
else
{
changed
.
put
(
file
,
code
);
}
}
return
new
Status
(
repo
.
getCurrentHEAD
().
get
().
getId
(),
changed
,
unmerged
);
}
}
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