grim/govcs
Clone
Summary
Browse
Changes
Graph
remove the Bookmark method from git
draft
2017-12-27, Gary Kramlich
e3e0b8f91448
remove the Bookmark method from git
// govcs
// Copyright 2017 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Package govcs is the entry point to using the govcs library.
package
govcs
import
(
"errors"
"bitbucket.org/rw_grim/govcs/git"
"bitbucket.org/rw_grim/govcs/hg"
"bitbucket.org/rw_grim/govcs/vcs"
)
type
detectorFunc
func
(
wd
string
)
vcs
.
VCS
var
(
detectors
=
[]
detectorFunc
{
git
.
Detect
,
hg
.
Detect
,
}
ErrNoRepositoryFound
=
errors
.
New
(
"no repository found"
)
)
// Detect will try to determine what version control system is in use in the
// given working directory and return a vcs.VCS instance for it.
func
Detect
(
wd
string
)
(
vcs
.
VCS
,
error
)
{
var
instance
vcs
.
VCS
for
_
,
detector
:=
range
detectors
{
inst
:=
detector
(
wd
)
// we found a VCS
if
inst
!=
nil
{
// if we found one previously, check who's root is longer so that
// we return the right vcs when they're nested.
// for example if we have
//
// foo/
// .git/
// bar/
// .hg/
//
// and we're testing bar, due to the order of the list we'd return
// a Git instance since it's first, but it really should be a
// mercurial instance.
if
instance
!=
nil
{
if
len
(
inst
.
Root
())
>
len
(
instance
.
Root
())
{
instance
=
inst
}
}
else
{
instance
=
inst
}
}
}
if
instance
!=
nil
{
return
instance
,
nil
}
return
nil
,
ErrNoRepositoryFound
}