-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.go
More file actions
130 lines (113 loc) · 2.87 KB
/
Copy pathgit.go
File metadata and controls
130 lines (113 loc) · 2.87 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package git
import (
"strings"
"time"
)
// Runner is the app's doorway to the installed git binary. The TUI calls
// Runner methods instead of building raw git commands itself.
type Runner struct {
Dir string
}
// FileStatus is one changed-file row from `git status --porcelain`.
type FileStatus struct {
Path string
OldPath string
Index byte
Worktree byte
Directory bool
}
// Commit is one commit row used by the in-TUI squash workflow.
type Commit struct {
Hash string
Subject string
}
// Stash is one row from `git stash list`.
type Stash struct {
Ref string
Subject string
}
// Release is one GitHub release row shown by the releases picker.
type Release struct {
Tag string
Name string
Published string
Draft bool
Prerelease bool
}
// ReleaseAsset is a downloadable file attached to a GitHub release.
type ReleaseAsset struct {
Name string
Size int64
ContentType string
URL string
}
// ReleaseDetail contains the full metadata and notes for one GitHub release.
type ReleaseDetail struct {
Release
Author string
Body string
URL string
TargetCommitish string
Created string
Assets []ReleaseAsset
}
// Staged reports whether Git says this file has staged changes.
func (f FileStatus) Staged() bool {
return f.Index != ' ' && f.Index != '?'
}
// Unstaged reports whether Git says this file has unstaged or untracked changes.
func (f FileStatus) Unstaged() bool {
return f.Worktree != ' ' || f.Index == '?'
}
// Label returns Git's two-letter status, such as "M " or "??".
func (f FileStatus) Label() string {
if f.Index == '?' {
return "??"
}
return string([]byte{f.Index, f.Worktree})
}
// DisplayPath returns the path label shown to users.
func (f FileStatus) DisplayPath() string {
if f.OldPath != "" {
return f.OldPath + " -> " + f.Path
}
if f.Directory {
return strings.TrimSuffix(f.Path, "/") + "/"
}
return f.Path
}
// GitPaths returns the path arguments Git needs for this status row.
func (f FileStatus) GitPaths() []string {
if f.OldPath != "" {
return []string{f.OldPath, f.Path}
}
if f.Path == "" {
return nil
}
return []string{f.Path}
}
// Deleted reports whether this row represents a removed tracked path.
func (f FileStatus) Deleted() bool {
return f.Index == 'D' || f.Worktree == 'D'
}
// Rename reports whether this row represents a rename or copy.
func (f FileStatus) Renamed() bool {
return f.OldPath != ""
}
// RepoInfo is the repository summary shown in the top status bar.
type RepoInfo struct {
Repo string
Branch string
Upstream string
User string
Ahead int
Behind int
Staged int
Unstaged int
LastPull time.Time
LastPullSet bool
}
// NewRunner creates a runner that executes Git in dir, or in the current directory.
func NewRunner(dir string) Runner {
return Runner{Dir: dir}
}