aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorAlberto Cortés <alberto@sourced.tech>2016-08-01 19:31:22 +0200
committerAlberto Cortés <alberto@sourced.tech>2016-08-01 19:31:22 +0200
commitb5613047f0d1fc6f53d5a8ad1a05415ca9c6a92a (patch)
tree1ae84ac6e7ab4b4c4dbdb2160d7a084b9fbc0185 /repository.go
parent49873428a53364a2a49cd521867d4fda59464911 (diff)
downloadgo-git-b5613047f0d1fc6f53d5a8ad1a05415ca9c6a92a.tar.gz
add head support for remote repos and more tests
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/repository.go b/repository.go
index 1342e7d..0cda947 100644
--- a/repository.go
+++ b/repository.go
@@ -219,9 +219,21 @@ func (r *Repository) Object(h core.Hash) (Object, error) {
}
}
-// Head returns the hash of the HEAD of the repository. If there is no
-// HEAD, it then returns the hash of the HEAD of the default remote. If
-// there is no default remote, it returns an error.
-func (r *Repository) Head() (core.Hash, error) {
+// Head returns the hash of the HEAD of the repository or the head of a
+// remote, if one is passed.
+func (r *Repository) Head(remote string) (core.Hash, error) {
+ if remote == "" {
+ return r.localHead()
+ }
+
+ rem, ok := r.Remotes[remote]
+ if !ok {
+ return core.ZeroHash, fmt.Errorf("unable to find remote %q", remote)
+ }
+
+ return rem.Head()
+}
+
+func (r *Repository) localHead() (core.Hash, error) {
return core.ZeroHash, nil
}