summaryrefslogtreecommitdiff
path: root/doAdd.go
blob: 10347a96a7a34fa0f5e5f1c5c14d5135728173d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"errors"
	"fmt"
	"os"
	"strings"

	"go.wit.com/lib/fhelp"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func workingDirToRepo() *gitpb.Repo {
	wd, _ := os.Getwd()
	for repo := range me.forge.Repos.IterAll() {
		if strings.HasPrefix(repo.FullPath, wd) {
			return repo
		}
	}
	return nil
}

func doAdd() (string, error) {
	var s string
	var err error

	wd, _ := os.Getwd()
	found := gitpb.NewRepos()
	for repo := range me.forge.Repos.IterAll() {
		if strings.HasPrefix(repo.FullPath, wd) {
			found.Append(repo)
		}
	}

	if found.Len() > 0 {
		footer := me.forge.PrintDefaultTB(found)
		log.Info(footer)
		return "This directory is already in a known repository", nil
	}

	s = fmt.Sprintf("Scan this directory (%s) for new .git repos?", wd)
	if !fhelp.QuestionUser(s) {
		// s, err = doModeMaster()
		err = errors.New("todo: scan dir")
	} else {
		err = errors.New("not acked")
	}
	return s, err
}