1
0
Fork 0

devtools/depotview: fix stale branches, clone bug

Change-Id: Ia2c680d511e3a8b632414caae3058db20d8231ba
master
q3k 2020-04-12 14:38:27 +02:00
parent 5bce7ce9fd
commit ebaa40894d
1 changed files with 10 additions and 3 deletions

View File

@ -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,