From e4851a801804091a3d3040791ad70b337be49463 Mon Sep 17 00:00:00 2001
From: Georg Seibt <seibt@fim.uni-passau.de>
Date: Fri, 21 Oct 2016 15:15:49 +0200
Subject: [PATCH] Return the actual name of the commit from its getId()
 function, this way Repository#checkout(Reference) will bring one 'on the
 branch' if the given Reference is a Branch.

---
 .../fim/seibt/gitwrapper/repo/Branch.java     | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

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 63b4798..f5be620 100644
--- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java
+++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Branch.java
@@ -1,11 +1,11 @@
 package de.uni_passau.fim.seibt.gitwrapper.repo;
 
-import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor;
-
 import java.util.Optional;
 import java.util.function.Function;
 import java.util.logging.Logger;
 
+import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor;
+
 /**
  *  A {@link Branch} is a named {@link Reference} to a git branch pointing to a {@link Commit}.
  */
@@ -48,21 +48,21 @@ public class Branch extends Reference {
     }
 
     /**
-     * Returns the id of the {@link Commit} this reference is currently pointing to.
+     * Returns the {@link Commit} this {@link Branch} is pointing at or an empty optional if there is an error.
      *
-     * @return the id of the {@link Commit} under this branch
+     * @return optionally the tip of this {@link Branch}
      */
-    @Override
-    public String getId() {
-        return repo.toHash(id).orElse(id);
+    public Optional<Commit> getTip() {
+        return repo.toHash(id).map(repo::getCommitUnchecked);
     }
 
     /**
-     * Reruns the branch name.
+     * Returns the name of this {@link Branch} e.g. 'master' or 'origin/master'.
      *
-     * @return the branch name
+     * @return the name of this {@link Branch}
      */
-    public String getName() {
+    @Override
+    public String getId() {
         return id;
     }
 }
-- 
GitLab