Skip to content

Commit 9a64b43

Browse files
author
Nate Smith
authored
Merge pull request cli#112 from github/rm-utils
Remove legacy code under `ui` and `utils`
2 parents 39a5dbc + 62bbcb2 commit 9a64b43

File tree

3 files changed

+0
-272
lines changed

3 files changed

+0
-272
lines changed

git/git.go

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io/ioutil"
7-
"os"
87
"os/exec"
98
"path/filepath"
109
"strings"
@@ -31,16 +30,6 @@ func Dir() (string, error) {
3130
return gitDir, nil
3231
}
3332

34-
func WorkdirName() (string, error) {
35-
toplevelCmd := exec.Command("git", "rev-parse", "--show-toplevel")
36-
output, err := utils.PrepareCmd(toplevelCmd).Output()
37-
dir := firstLine(output)
38-
if dir == "" {
39-
return "", fmt.Errorf("unable to determine git working directory")
40-
}
41-
return dir, err
42-
}
43-
4433
func VerifyRef(ref string) bool {
4534
showRef := exec.Command("git", "show-ref", "--verify", "--quiet", ref)
4635
err := utils.PrepareCmd(showRef).Run()
@@ -73,72 +62,10 @@ func BranchAtRef(paths ...string) (name string, err error) {
7362
return
7463
}
7564

76-
func Editor() (string, error) {
77-
varCmd := exec.Command("git", "var", "GIT_EDITOR")
78-
output, err := utils.PrepareCmd(varCmd).Output()
79-
if err != nil {
80-
return "", fmt.Errorf("Can't load git var: GIT_EDITOR")
81-
}
82-
83-
return os.ExpandEnv(firstLine(output)), nil
84-
}
85-
8665
func Head() (string, error) {
8766
return BranchAtRef("HEAD")
8867
}
8968

90-
func SymbolicFullName(name string) (string, error) {
91-
parseCmd := exec.Command("git", "rev-parse", "--symbolic-full-name", name)
92-
output, err := utils.PrepareCmd(parseCmd).Output()
93-
if err != nil {
94-
return "", fmt.Errorf("Unknown revision or path not in the working tree: %s", name)
95-
}
96-
97-
return firstLine(output), nil
98-
}
99-
100-
func CommentChar(text string) (string, error) {
101-
char, err := Config("core.commentchar")
102-
if err != nil {
103-
return "#", nil
104-
} else if char == "auto" {
105-
lines := strings.Split(text, "\n")
106-
commentCharCandidates := strings.Split("#;@!$%^&|:", "")
107-
candidateLoop:
108-
for _, candidate := range commentCharCandidates {
109-
for _, line := range lines {
110-
if strings.HasPrefix(line, candidate) {
111-
continue candidateLoop
112-
}
113-
}
114-
return candidate, nil
115-
}
116-
return "", fmt.Errorf("unable to select a comment character that is not used in the current message")
117-
} else {
118-
return char, nil
119-
}
120-
}
121-
122-
func Show(sha string) (string, error) {
123-
cmd := exec.Command("git", "-c", "log.showSignature=false", "show", "-s", "--format=%s%n%+b", sha)
124-
output, err := utils.PrepareCmd(cmd).Output()
125-
return strings.TrimSpace(string(output)), err
126-
}
127-
128-
func Log(sha1, sha2 string) (string, error) {
129-
shaRange := fmt.Sprintf("%s...%s", sha1, sha2)
130-
cmd := exec.Command(
131-
"-c", "log.showSignature=false", "log", "--no-color",
132-
"--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b",
133-
"--cherry", shaRange)
134-
outputs, err := utils.PrepareCmd(cmd).Output()
135-
if err != nil {
136-
return "", fmt.Errorf("Can't load git log %s..%s", sha1, sha2)
137-
}
138-
139-
return string(outputs), nil
140-
}
141-
14269
func listRemotes() ([]string, error) {
14370
remoteCmd := exec.Command("git", "remote", "-v")
14471
output, err := utils.PrepareCmd(remoteCmd).Output()
@@ -156,34 +83,6 @@ func Config(name string) (string, error) {
15683

15784
}
15885

159-
func ConfigAll(name string) ([]string, error) {
160-
mode := "--get-all"
161-
if strings.Contains(name, "*") {
162-
mode = "--get-regexp"
163-
}
164-
165-
configCmd := exec.Command("git", "config", mode, name)
166-
output, err := utils.PrepareCmd(configCmd).Output()
167-
if err != nil {
168-
return nil, fmt.Errorf("Unknown config %s", name)
169-
}
170-
return outputLines(output), nil
171-
}
172-
173-
func LocalBranches() ([]string, error) {
174-
branchesCmd := exec.Command("git", "branch", "--list")
175-
output, err := utils.PrepareCmd(branchesCmd).Output()
176-
if err != nil {
177-
return nil, err
178-
}
179-
180-
branches := []string{}
181-
for _, branch := range outputLines(output) {
182-
branches = append(branches, branch[2:])
183-
}
184-
return branches, nil
185-
}
186-
18786
var GitCommand = func(args ...string) *exec.Cmd {
18887
return exec.Command("git", args...)
18988
}

ui/ui.go

Lines changed: 0 additions & 98 deletions
This file was deleted.

utils/utils.go

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,13 @@ package utils
22

33
import (
44
"errors"
5-
"fmt"
65
"os"
76
"os/exec"
8-
"path/filepath"
97
"runtime"
10-
"strings"
11-
"time"
128

13-
"github.com/github/gh-cli/ui"
149
"github.com/kballard/go-shellquote"
1510
)
1611

17-
var timeNow = time.Now
18-
19-
func Check(err error) {
20-
if err != nil {
21-
ui.Errorln(err)
22-
os.Exit(1)
23-
}
24-
}
25-
26-
func ConcatPaths(paths ...string) string {
27-
return strings.Join(paths, "/")
28-
}
29-
3012
func OpenInBrowser(url string) error {
3113
browser := os.Getenv("BROWSER")
3214
if browser == "" {
@@ -69,58 +51,3 @@ func searchBrowserLauncher(goos string) (browser string) {
6951

7052
return browser
7153
}
72-
73-
func CommandPath(cmd string) (string, error) {
74-
if runtime.GOOS == "windows" {
75-
cmd = cmd + ".exe"
76-
}
77-
78-
path, err := exec.LookPath(cmd)
79-
if err != nil {
80-
return "", err
81-
}
82-
83-
path, err = filepath.Abs(path)
84-
if err != nil {
85-
return "", err
86-
}
87-
88-
return filepath.EvalSymlinks(path)
89-
}
90-
91-
func TimeAgo(t time.Time) string {
92-
duration := timeNow().Sub(t)
93-
minutes := duration.Minutes()
94-
hours := duration.Hours()
95-
days := hours / 24
96-
months := days / 30
97-
years := months / 12
98-
99-
var val int
100-
var unit string
101-
102-
if minutes < 1 {
103-
return "now"
104-
} else if hours < 1 {
105-
val = int(minutes)
106-
unit = "minute"
107-
} else if days < 1 {
108-
val = int(hours)
109-
unit = "hour"
110-
} else if months < 1 {
111-
val = int(days)
112-
unit = "day"
113-
} else if years < 1 {
114-
val = int(months)
115-
unit = "month"
116-
} else {
117-
val = int(years)
118-
unit = "year"
119-
}
120-
121-
var plural string
122-
if val > 1 {
123-
plural = "s"
124-
}
125-
return fmt.Sprintf("%d %s%s ago", val, unit, plural)
126-
}

0 commit comments

Comments
 (0)