forked from hswaw/hscloud
Merge "devtools/depotview: fix stale branches, clone bug"
commit
ac43b3edac
|
@ -46,8 +46,10 @@ func New(remote string) *Service {
|
|||
|
||||
func (s *Service) ensureRepo(ctx context.Context) error {
|
||||
// Clone repository if necessary.
|
||||
// Use background context - we don't want this to get canceled.
|
||||
if s.repo == nil {
|
||||
repo, err := git.CloneContext(ctx, s.storer, nil, &git.CloneOptions{
|
||||
glog.Infof("Cloning %q...", s.remote)
|
||||
repo, err := git.CloneContext(context.Background(), s.storer, nil, &git.CloneOptions{
|
||||
URL: s.remote,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -55,14 +57,19 @@ func (s *Service) ensureRepo(ctx context.Context) error {
|
|||
return status.Error(codes.Unavailable, "could not clone repository")
|
||||
}
|
||||
s.repo = repo
|
||||
glog.Infof("Clone done.")
|
||||
}
|
||||
|
||||
// We could've gotten canceled by now.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Fetch if necessary.
|
||||
if time.Since(s.lastFetch) > 10*time.Second {
|
||||
glog.Infof("Fetching...")
|
||||
err := s.repo.FetchContext(ctx, &git.FetchOptions{
|
||||
RefSpecs: []config.RefSpec{
|
||||
config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
|
||||
config.RefSpec("+refs/heads/*:refs/heads/*"),
|
||||
config.RefSpec("+refs/changes/*:refs/changes/*"),
|
||||
},
|
||||
Force: true,
|
||||
|
|
Loading…
Reference in New Issue