-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Use git command instead of exec.Cmd in blame #22098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7398108
Use git command instead of exec.Cmd in blame
lunny 7e4a66d
as per wxiaoguang
lunny 6823592
Fix test
lunny 9ffabf0
Merge branch 'main' into lunny/blame_cmd
lunny c558e82
Merge branch 'main' into lunny/blame_cmd
lunny 4a5e64d
Merge branch 'main' into lunny/blame_cmd
lunny 542927f
Make git command safer
lunny 3c7ae7e
Merge branch 'main' into lunny/blame_cmd
lunny fa72036
Merge branch 'lunny/blame_cmd' of github.com:lunny/gitea into lunny/b…
lunny a79f39e
Merge branch 'main' into lunny/blame_cmd
lunny 8d4001a
Merge branch 'main' into lunny/blame_cmd
lunny e05232f
Use context timeout in blame command
lunny c171361
Merge branch 'main' into lunny/blame_cmd
lunny 6ea3877
Merge branch 'lunny/blame_cmd' of github.com:lunny/gitea into lunny/b…
lunny 271faf7
Update modules/git/blame.go
lunny a4e669b
Merge branch 'main' into lunny/blame_cmd
lunny 120b783
Merge branch 'main' into lunny/blame_cmd
lunny 68658ad
Merge branch 'main' into lunny/blame_cmd
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,139 +5,36 @@ package git | |
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const exampleBlame = ` | ||
4b92a6c2df28054ad766bc262f308db9f6066596 1 1 1 | ||
author Unknown | ||
author-mail <[email protected]> | ||
author-time 1392833071 | ||
author-tz -0500 | ||
committer Unknown | ||
committer-mail <[email protected]> | ||
committer-time 1392833071 | ||
committer-tz -0500 | ||
summary Add code of delete user | ||
previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go | ||
filename gogs.go | ||
// Copyright 2014 The Gogs Authors. All rights reserved. | ||
ce21ed6c3490cdfad797319cbb1145e2330a8fef 2 2 1 | ||
author Joubert RedRat | ||
author-mail <[email protected]> | ||
author-time 1482322397 | ||
author-tz -0200 | ||
committer Lunny Xiao | ||
committer-mail <[email protected]> | ||
committer-time 1482322397 | ||
committer-tz +0800 | ||
summary Remove remaining Gogs reference on locales and cmd (#430) | ||
previous 618407c018cdf668ceedde7454c42fb22ba422d8 main.go | ||
filename main.go | ||
// Copyright 2016 The Gitea Authors. All rights reserved. | ||
4b92a6c2df28054ad766bc262f308db9f6066596 2 3 2 | ||
author Unknown | ||
author-mail <[email protected]> | ||
author-time 1392833071 | ||
author-tz -0500 | ||
committer Unknown | ||
committer-mail <[email protected]> | ||
committer-time 1392833071 | ||
committer-tz -0500 | ||
summary Add code of delete user | ||
previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go | ||
filename gogs.go | ||
// Use of this source code is governed by a MIT-style | ||
4b92a6c2df28054ad766bc262f308db9f6066596 3 4 | ||
author Unknown | ||
author-mail <[email protected]> | ||
author-time 1392833071 | ||
author-tz -0500 | ||
committer Unknown | ||
committer-mail <[email protected]> | ||
committer-time 1392833071 | ||
committer-tz -0500 | ||
summary Add code of delete user | ||
previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go | ||
filename gogs.go | ||
// license that can be found in the LICENSE file. | ||
|
||
e2aa991e10ffd924a828ec149951f2f20eecead2 6 6 2 | ||
author Lunny Xiao | ||
author-mail <[email protected]> | ||
author-time 1478872595 | ||
author-tz +0800 | ||
committer Sandro Santilli | ||
committer-mail <[email protected]> | ||
committer-time 1478872595 | ||
committer-tz +0100 | ||
summary ask for go get from code.gitea.io/gitea and change gogs to gitea on main file (#146) | ||
previous 5fc370e332171b8658caed771b48585576f11737 main.go | ||
filename main.go | ||
// Gitea (git with a cup of tea) is a painless self-hosted Git Service. | ||
e2aa991e10ffd924a828ec149951f2f20eecead2 7 7 | ||
package main // import "code.gitea.io/gitea" | ||
` | ||
|
||
func TestReadingBlameOutput(t *testing.T) { | ||
tempFile, err := os.CreateTemp("", ".txt") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer tempFile.Close() | ||
|
||
if _, err = tempFile.WriteString(exampleBlame); err != nil { | ||
panic(err) | ||
} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
blameReader, err := createBlameReader(ctx, "", "cat", tempFile.Name()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
blameReader, err := CreateBlameReader(ctx, "./tests/repos/repo5_pulls", "f32b0a9dfd09a60f616f29158f772cedd89942d2", "README.md") | ||
assert.NoError(t, err) | ||
defer blameReader.Close() | ||
|
||
parts := []*BlamePart{ | ||
{ | ||
"4b92a6c2df28054ad766bc262f308db9f6066596", | ||
[]string{ | ||
"// Copyright 2014 The Gogs Authors. All rights reserved.", | ||
}, | ||
}, | ||
{ | ||
"ce21ed6c3490cdfad797319cbb1145e2330a8fef", | ||
[]string{ | ||
"// Copyright 2016 The Gitea Authors. All rights reserved.", | ||
}, | ||
}, | ||
{ | ||
"4b92a6c2df28054ad766bc262f308db9f6066596", | ||
"72866af952e98d02a73003501836074b286a78f6", | ||
[]string{ | ||
"// Use of this source code is governed by a MIT-style", | ||
"// license that can be found in the LICENSE file.", | ||
"", | ||
"# test_repo", | ||
"Test repository for testing migration from github to gitea", | ||
}, | ||
}, | ||
{ | ||
"e2aa991e10ffd924a828ec149951f2f20eecead2", | ||
[]string{ | ||
"// Gitea (git with a cup of tea) is a painless self-hosted Git Service.", | ||
"package main // import \"code.gitea.io/gitea\"", | ||
}, | ||
"f32b0a9dfd09a60f616f29158f772cedd89942d2", | ||
[]string{}, | ||
}, | ||
nil, | ||
} | ||
|
||
for _, part := range parts { | ||
actualPart, err := blameReader.NextPart() | ||
if err != nil { | ||
panic(err) | ||
} | ||
assert.NoError(t, err) | ||
assert.Equal(t, part, actualPart) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.