Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
0be001f7
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0be001f7
编写于
5月 09, 2019
作者:
M
Mislav Marohnić
提交者:
GitHub
5月 09, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2135 from github/git-trace
Enable GIT_TRACE
上级
16ccde1a
b38a3185
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
105 addition
and
72 deletion
+105
-72
cmd/cmd.go
cmd/cmd.go
+9
-0
commands/pull_request.go
commands/pull_request.go
+2
-2
git/git.go
git/git.go
+94
-65
github/util.go
github/util.go
+0
-5
未找到文件。
cmd/cmd.go
浏览文件 @
0be001f7
...
@@ -39,6 +39,15 @@ func (cmd *Cmd) WithArgs(args ...string) *Cmd {
...
@@ -39,6 +39,15 @@ func (cmd *Cmd) WithArgs(args ...string) *Cmd {
return
cmd
return
cmd
}
}
func
(
cmd
*
Cmd
)
Output
()
(
string
,
error
)
{
verboseLog
(
cmd
)
c
:=
exec
.
Command
(
cmd
.
Name
,
cmd
.
Args
...
)
c
.
Stderr
=
cmd
.
Stderr
output
,
err
:=
c
.
Output
()
return
string
(
output
),
err
}
func
(
cmd
*
Cmd
)
CombinedOutput
()
(
string
,
error
)
{
func
(
cmd
*
Cmd
)
CombinedOutput
()
(
string
,
error
)
{
verboseLog
(
cmd
)
verboseLog
(
cmd
)
output
,
err
:=
exec
.
Command
(
cmd
.
Name
,
cmd
.
Args
...
)
.
CombinedOutput
()
output
,
err
:=
exec
.
Command
(
cmd
.
Name
,
cmd
.
Args
...
)
.
CombinedOutput
()
...
...
commands/pull_request.go
浏览文件 @
0be001f7
...
@@ -187,8 +187,8 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -187,8 +187,8 @@ func pullRequest(cmd *Command, args *Args) {
force
:=
args
.
Flag
.
Bool
(
"--force"
)
force
:=
args
.
Flag
.
Bool
(
"--force"
)
if
!
force
&&
trackedBranch
!=
nil
{
if
!
force
&&
trackedBranch
!=
nil
{
remoteCommits
,
_
:=
git
.
RefList
(
trackedBranch
.
LongName
(),
""
)
remoteCommits
,
err
:=
git
.
RefList
(
trackedBranch
.
LongName
(),
""
)
if
len
(
remoteCommits
)
>
0
{
if
err
==
nil
&&
len
(
remoteCommits
)
>
0
{
err
=
fmt
.
Errorf
(
"Aborted: %d commits are not yet pushed to %s"
,
len
(
remoteCommits
),
trackedBranch
.
LongName
())
err
=
fmt
.
Errorf
(
"Aborted: %d commits are not yet pushed to %s"
,
len
(
remoteCommits
),
trackedBranch
.
LongName
())
err
=
fmt
.
Errorf
(
"%s
\n
(use `-f` to force submit a pull request anyway)"
,
err
)
err
=
fmt
.
Errorf
(
"%s
\n
(use `-f` to force submit a pull request anyway)"
,
err
)
utils
.
Check
(
err
)
utils
.
Check
(
err
)
...
...
git/git.go
浏览文件 @
0be001f7
...
@@ -13,12 +13,12 @@ import (
...
@@ -13,12 +13,12 @@ import (
var
GlobalFlags
[]
string
var
GlobalFlags
[]
string
func
Version
()
(
string
,
error
)
{
func
Version
()
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
"version"
)
versionCmd
:=
gitCmd
(
"version"
)
if
err
==
nil
{
output
,
err
:=
versionCmd
.
Output
()
return
output
[
0
],
nil
if
err
!=
nil
{
}
else
{
return
""
,
fmt
.
Errorf
(
"error running git version: %s"
,
err
)
return
""
,
fmt
.
Errorf
(
"error running git version: %s"
,
err
)
}
}
return
firstLine
(
output
),
nil
}
}
var
cachedDir
string
var
cachedDir
string
...
@@ -28,7 +28,9 @@ func Dir() (string, error) {
...
@@ -28,7 +28,9 @@ func Dir() (string, error) {
return
cachedDir
,
nil
return
cachedDir
,
nil
}
}
output
,
err
:=
gitOutput
(
"rev-parse"
,
"-q"
,
"--git-dir"
)
dirCmd
:=
gitCmd
(
"rev-parse"
,
"-q"
,
"--git-dir"
)
dirCmd
.
Stderr
=
nil
output
,
err
:=
dirCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Not a git repository (or any of the parent directories): .git"
)
return
""
,
fmt
.
Errorf
(
"Not a git repository (or any of the parent directories): .git"
)
}
}
...
@@ -45,7 +47,7 @@ func Dir() (string, error) {
...
@@ -45,7 +47,7 @@ func Dir() (string, error) {
}
}
}
}
gitDir
:=
output
[
0
]
gitDir
:=
firstLine
(
output
)
if
!
filepath
.
IsAbs
(
gitDir
)
{
if
!
filepath
.
IsAbs
(
gitDir
)
{
if
chdir
!=
""
{
if
chdir
!=
""
{
...
@@ -65,24 +67,25 @@ func Dir() (string, error) {
...
@@ -65,24 +67,25 @@ func Dir() (string, error) {
}
}
func
WorkdirName
()
(
string
,
error
)
{
func
WorkdirName
()
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
"rev-parse"
,
"--show-toplevel"
)
toplevelCmd
:=
gitCmd
(
"rev-parse"
,
"--show-toplevel"
)
if
err
==
nil
{
toplevelCmd
.
Stderr
=
nil
if
len
(
output
)
>
0
{
output
,
err
:=
toplevelCmd
.
Output
()
return
output
[
0
],
nil
dir
:=
firstLine
(
output
)
}
else
{
if
dir
==
""
{
return
""
,
fmt
.
Errorf
(
"unable to determine git working directory"
)
return
""
,
fmt
.
Errorf
(
"unable to determine git working directory"
)
}
}
else
{
return
""
,
err
}
}
return
dir
,
err
}
}
func
HasFile
(
segments
...
string
)
bool
{
func
HasFile
(
segments
...
string
)
bool
{
// The blessed way to resolve paths within git dir since Git 2.5.0
// The blessed way to resolve paths within git dir since Git 2.5.0
output
,
err
:=
gitOutput
(
"rev-parse"
,
"-q"
,
"--git-path"
,
filepath
.
Join
(
segments
...
))
pathCmd
:=
gitCmd
(
"rev-parse"
,
"-q"
,
"--git-path"
,
filepath
.
Join
(
segments
...
))
if
err
==
nil
&&
output
[
0
]
!=
"--git-path"
{
pathCmd
.
Stderr
=
nil
if
_
,
err
:=
os
.
Stat
(
output
[
0
]);
err
==
nil
{
if
output
,
err
:=
pathCmd
.
Output
();
err
==
nil
{
return
true
if
lines
:=
outputLines
(
output
);
len
(
lines
)
==
1
{
if
_
,
err
:=
os
.
Stat
(
lines
[
0
]);
err
==
nil
{
return
true
}
}
}
}
}
...
@@ -129,12 +132,14 @@ func BranchAtRef(paths ...string) (name string, err error) {
...
@@ -129,12 +132,14 @@ func BranchAtRef(paths ...string) (name string, err error) {
}
}
func
Editor
()
(
string
,
error
)
{
func
Editor
()
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
"var"
,
"GIT_EDITOR"
)
varCmd
:=
gitCmd
(
"var"
,
"GIT_EDITOR"
)
varCmd
.
Stderr
=
nil
output
,
err
:=
varCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Can't load git var: GIT_EDITOR"
)
return
""
,
fmt
.
Errorf
(
"Can't load git var: GIT_EDITOR"
)
}
}
return
os
.
ExpandEnv
(
output
[
0
]
),
nil
return
os
.
ExpandEnv
(
firstLine
(
output
)
),
nil
}
}
func
Head
()
(
string
,
error
)
{
func
Head
()
(
string
,
error
)
{
...
@@ -142,40 +147,52 @@ func Head() (string, error) {
...
@@ -142,40 +147,52 @@ func Head() (string, error) {
}
}
func
SymbolicFullName
(
name
string
)
(
string
,
error
)
{
func
SymbolicFullName
(
name
string
)
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
"rev-parse"
,
"--symbolic-full-name"
,
name
)
parseCmd
:=
gitCmd
(
"rev-parse"
,
"--symbolic-full-name"
,
name
)
parseCmd
.
Stderr
=
nil
output
,
err
:=
parseCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Unknown revision or path not in the working tree: %s"
,
name
)
return
""
,
fmt
.
Errorf
(
"Unknown revision or path not in the working tree: %s"
,
name
)
}
}
return
output
[
0
]
,
nil
return
firstLine
(
output
)
,
nil
}
}
func
Ref
(
ref
string
)
(
string
,
error
)
{
func
Ref
(
ref
string
)
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
"rev-parse"
,
"-q"
,
ref
)
parseCmd
:=
gitCmd
(
"rev-parse"
,
"-q"
,
ref
)
parseCmd
.
Stderr
=
nil
output
,
err
:=
parseCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Unknown revision or path not in the working tree: %s"
,
ref
)
return
""
,
fmt
.
Errorf
(
"Unknown revision or path not in the working tree: %s"
,
ref
)
}
}
return
output
[
0
]
,
nil
return
firstLine
(
output
)
,
nil
}
}
func
RefList
(
a
,
b
string
)
([]
string
,
error
)
{
func
RefList
(
a
,
b
string
)
([]
string
,
error
)
{
ref
:=
fmt
.
Sprintf
(
"%s...%s"
,
a
,
b
)
ref
:=
fmt
.
Sprintf
(
"%s...%s"
,
a
,
b
)
output
,
err
:=
gitOutput
(
"rev-list"
,
"--cherry-pick"
,
"--right-only"
,
"--no-merges"
,
ref
)
listCmd
:=
gitCmd
(
"rev-list"
,
"--cherry-pick"
,
"--right-only"
,
"--no-merges"
,
ref
)
listCmd
.
Stderr
=
nil
output
,
err
:=
listCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
string
{}
,
fmt
.
Errorf
(
"Can't load rev-list for %s"
,
ref
)
return
nil
,
fmt
.
Errorf
(
"Can't load rev-list for %s"
,
ref
)
}
}
return
output
,
nil
return
output
Lines
(
output
)
,
nil
}
}
func
NewRange
(
a
,
b
string
)
(
*
Range
,
error
)
{
func
NewRange
(
a
,
b
string
)
(
*
Range
,
error
)
{
output
,
err
:=
gitOutput
(
"rev-parse"
,
"-q"
,
a
,
b
)
parseCmd
:=
gitCmd
(
"rev-parse"
,
"-q"
,
a
,
b
)
parseCmd
.
Stderr
=
nil
output
,
err
:=
parseCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
&
Range
{
output
[
0
],
output
[
1
]},
nil
lines
:=
outputLines
(
output
)
if
len
(
lines
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"Can't parse range %s..%s"
,
a
,
b
)
}
return
&
Range
{
lines
[
0
],
lines
[
1
]},
nil
}
}
type
Range
struct
{
type
Range
struct
{
...
@@ -216,13 +233,12 @@ func CommentChar(text string) (string, error) {
...
@@ -216,13 +233,12 @@ func CommentChar(text string) (string, error) {
func
Show
(
sha
string
)
(
string
,
error
)
{
func
Show
(
sha
string
)
(
string
,
error
)
{
cmd
:=
cmd
.
New
(
"git"
)
cmd
:=
cmd
.
New
(
"git"
)
cmd
.
Stderr
=
nil
cmd
.
WithArg
(
"-c"
)
.
WithArg
(
"log.showSignature=false"
)
cmd
.
WithArg
(
"-c"
)
.
WithArg
(
"log.showSignature=false"
)
cmd
.
WithArg
(
"show"
)
.
WithArg
(
"-s"
)
.
WithArg
(
"--format=%s%n%+b"
)
.
WithArg
(
sha
)
cmd
.
WithArg
(
"show"
)
.
WithArg
(
"-s"
)
.
WithArg
(
"--format=%s%n%+b"
)
.
WithArg
(
sha
)
output
,
err
:=
cmd
.
CombinedOutput
()
output
,
err
:=
cmd
.
Output
()
output
=
strings
.
TrimSpace
(
output
)
return
strings
.
TrimSpace
(
output
),
err
return
output
,
err
}
}
func
Log
(
sha1
,
sha2
string
)
(
string
,
error
)
{
func
Log
(
sha1
,
sha2
string
)
(
string
,
error
)
{
...
@@ -233,7 +249,7 @@ func Log(sha1, sha2 string) (string, error) {
...
@@ -233,7 +249,7 @@ func Log(sha1, sha2 string) (string, error) {
shaRange
:=
fmt
.
Sprintf
(
"%s...%s"
,
sha1
,
sha2
)
shaRange
:=
fmt
.
Sprintf
(
"%s...%s"
,
sha1
,
sha2
)
execCmd
.
WithArg
(
shaRange
)
execCmd
.
WithArg
(
shaRange
)
outputs
,
err
:=
execCmd
.
Combined
Output
()
outputs
,
err
:=
execCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Can't load git log %s..%s"
,
sha1
,
sha2
)
return
""
,
fmt
.
Errorf
(
"Can't load git log %s..%s"
,
sha1
,
sha2
)
}
}
...
@@ -242,7 +258,10 @@ func Log(sha1, sha2 string) (string, error) {
...
@@ -242,7 +258,10 @@ func Log(sha1, sha2 string) (string, error) {
}
}
func
Remotes
()
([]
string
,
error
)
{
func
Remotes
()
([]
string
,
error
)
{
return
gitOutput
(
"remote"
,
"-v"
)
remoteCmd
:=
gitCmd
(
"remote"
,
"-v"
)
remoteCmd
.
Stderr
=
nil
output
,
err
:=
remoteCmd
.
Output
()
return
outputLines
(
output
),
err
}
}
func
Config
(
name
string
)
(
string
,
error
)
{
func
Config
(
name
string
)
(
string
,
error
)
{
...
@@ -255,11 +274,12 @@ func ConfigAll(name string) ([]string, error) {
...
@@ -255,11 +274,12 @@ func ConfigAll(name string) ([]string, error) {
mode
=
"--get-regexp"
mode
=
"--get-regexp"
}
}
lines
,
err
:=
gitOutput
(
gitConfigCommand
([]
string
{
mode
,
name
})
...
)
configCmd
:=
gitCmd
(
gitConfigCommand
([]
string
{
mode
,
name
})
...
)
output
,
err
:=
configCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Unknown config %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"Unknown config %s"
,
name
)
}
}
return
lines
,
err
return
outputLines
(
output
),
nil
}
}
func
GlobalConfig
(
name
string
)
(
string
,
error
)
{
func
GlobalConfig
(
name
string
)
(
string
,
error
)
{
...
@@ -272,20 +292,19 @@ func SetGlobalConfig(name, value string) error {
...
@@ -272,20 +292,19 @@ func SetGlobalConfig(name, value string) error {
}
}
func
gitGetConfig
(
args
...
string
)
(
string
,
error
)
{
func
gitGetConfig
(
args
...
string
)
(
string
,
error
)
{
output
,
err
:=
gitOutput
(
gitConfigCommand
(
args
)
...
)
configCmd
:=
gitCmd
(
gitConfigCommand
(
args
)
...
)
output
,
err
:=
configCmd
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Unknown config %s"
,
args
[
len
(
args
)
-
1
])
return
""
,
fmt
.
Errorf
(
"Unknown config %s"
,
args
[
len
(
args
)
-
1
])
}
}
if
len
(
output
)
==
0
{
return
firstLine
(
output
),
nil
return
""
,
nil
}
return
output
[
0
],
nil
}
}
func
gitConfig
(
args
...
string
)
([]
string
,
error
)
{
func
gitConfig
(
args
...
string
)
([]
string
,
error
)
{
return
gitOutput
(
gitConfigCommand
(
args
)
...
)
configCmd
:=
gitCmd
(
gitConfigCommand
(
args
)
...
)
output
,
err
:=
configCmd
.
Output
()
return
outputLines
(
output
),
err
}
}
func
gitConfigCommand
(
args
[]
string
)
[]
string
{
func
gitConfigCommand
(
args
[]
string
)
[]
string
{
...
@@ -319,27 +338,34 @@ func IsGitDir(dir string) bool {
...
@@ -319,27 +338,34 @@ func IsGitDir(dir string) bool {
}
}
func
LocalBranches
()
([]
string
,
error
)
{
func
LocalBranches
()
([]
string
,
error
)
{
lines
,
err
:=
gitOutput
(
"branch"
,
"--list"
)
branchesCmd
:=
gitCmd
(
"branch"
,
"--list"
)
if
err
==
nil
{
output
,
err
:=
branchesCmd
.
Output
()
for
i
,
line
:=
range
lines
{
if
err
!=
nil
{
lines
[
i
]
=
strings
.
TrimPrefix
(
line
,
"* "
)
return
nil
,
err
lines
[
i
]
=
strings
.
TrimPrefix
(
lines
[
i
],
" "
)
}
}
}
return
lines
,
err
}
func
gitOutput
(
input
...
string
)
(
outputs
[]
string
,
err
error
)
{
branches
:=
[]
string
{}
cmd
:=
gitCmd
(
input
...
)
for
_
,
branch
:=
range
outputLines
(
output
)
{
branches
=
append
(
branches
,
branch
[
2
:
])
}
return
branches
,
nil
}
out
,
err
:=
cmd
.
CombinedOutput
()
func
outputLines
(
output
string
)
[]
string
{
for
_
,
line
:=
range
strings
.
Split
(
out
,
"
\n
"
)
{
output
=
strings
.
TrimSuffix
(
output
,
"
\n
"
)
if
strings
.
TrimSpace
(
line
)
!=
""
{
if
output
==
""
{
outputs
=
append
(
outputs
,
string
(
line
))
return
[]
string
{}
}
}
else
{
return
strings
.
Split
(
output
,
"
\n
"
)
}
}
}
return
outputs
,
err
func
firstLine
(
output
string
)
string
{
if
i
:=
strings
.
Index
(
output
,
"
\n
"
);
i
>=
0
{
return
output
[
0
:
i
]
}
else
{
return
output
}
}
}
func
gitCmd
(
args
...
string
)
*
cmd
.
Cmd
{
func
gitCmd
(
args
...
string
)
*
cmd
.
Cmd
{
...
@@ -357,15 +383,18 @@ func gitCmd(args ...string) *cmd.Cmd {
...
@@ -357,15 +383,18 @@ func gitCmd(args ...string) *cmd.Cmd {
}
}
func
IsBuiltInGitCommand
(
command
string
)
bool
{
func
IsBuiltInGitCommand
(
command
string
)
bool
{
helpCommandOutput
,
err
:=
gitOutput
(
"help"
,
"--no-verbose"
,
"-a"
)
helpCommand
:=
gitCmd
(
"help"
,
"--no-verbose"
,
"-a"
)
helpCommand
.
Stderr
=
nil
helpCommandOutput
,
err
:=
helpCommand
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
// support git versions that don't recognize --no-verbose
// support git versions that don't recognize --no-verbose
helpCommandOutput
,
err
=
gitOutput
(
"help"
,
"-a"
)
helpCommand
:=
gitCmd
(
"help"
,
"-a"
)
helpCommandOutput
,
err
=
helpCommand
.
Output
()
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
}
}
for
_
,
helpCommandOutputLine
:=
range
helpCommandOutput
{
for
_
,
helpCommandOutputLine
:=
range
outputLines
(
helpCommandOutput
)
{
if
strings
.
HasPrefix
(
helpCommandOutputLine
,
" "
)
{
if
strings
.
HasPrefix
(
helpCommandOutputLine
,
" "
)
{
for
_
,
gitCommand
:=
range
strings
.
Split
(
helpCommandOutputLine
,
" "
)
{
for
_
,
gitCommand
:=
range
strings
.
Split
(
helpCommandOutputLine
,
" "
)
{
if
gitCommand
==
command
{
if
gitCommand
==
command
{
...
...
github/util.go
浏览文件 @
0be001f7
...
@@ -10,10 +10,5 @@ func IsHttpsProtocol() bool {
...
@@ -10,10 +10,5 @@ func IsHttpsProtocol() bool {
return
true
return
true
}
}
httpClone
,
_
:=
git
.
Config
(
"--bool hub.http-clone"
)
if
httpClone
==
"true"
{
return
true
}
return
false
return
false
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录