diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java index 45a6134fc15b84ad0d2653e77f3296b3fd1574f7..32abd4f209858e874173537bae462e9711d0db82 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java @@ -7,7 +7,7 @@ import java.util.function.Function; public class Branch extends Reference { - public Branch(Repository repo, String name) { + Branch(Repository repo, String name) { super(repo, name); } diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java index bfc74d241b6856cfaca971b26073d2cd77293ea0..61fb66b43b5bbeb763f049e1f3c5450c215303f0 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java @@ -49,6 +49,7 @@ public class Repository { private File dir; private Map<String, Commit> commits; + private Map<String, Branch> branches; /** * Constructs a new {@link Repository}. @@ -73,6 +74,7 @@ public class Repository { this.commits = new HashMap<>(); this.commits.put(DummyCommit.DUMMY_COMMIT_ID, new DummyCommit(this)); + this.branches = new HashMap<>(); } /** @@ -228,6 +230,18 @@ public class Repository { return catFile.map(toBoolean).orElse(false); } + public Optional<Branch> getBranch(String name) { + if (branches.containsKey(name)) { + return Optional.of(branches.get(name)); + } + + if (!isBranch(name)) { + return Optional.empty(); + } + + return Optional.of(branches.computeIfAbsent(name, theName -> new Branch(this, theName))); + } + /** * Determines whether the given name designates a branch. *