Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
- Loading branch information
1 parent
dba8aad
commit fa40794
Showing
4 changed files
with
85 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-git/go-git/v5" | ||
. "github.com/go-git/go-git/v5/_examples" | ||
) | ||
|
||
// Basic example of how to blame a repository. | ||
func main() { | ||
CheckArgs("<url>", "<file_to_blame>") | ||
url := os.Args[1] | ||
path := os.Args[2] | ||
|
||
tmp, err := os.MkdirTemp("", "go-git-blame-*") | ||
CheckIfError(err) | ||
|
||
defer os.RemoveAll(tmp) | ||
|
||
// Clone the given repository. | ||
Info("git clone %s %s", url, tmp) | ||
r, err := git.PlainClone( | ||
tmp, | ||
false, | ||
&git.CloneOptions{ | ||
URL: url, | ||
Tags: git.NoTags, | ||
}, | ||
) | ||
CheckIfError(err) | ||
|
||
// Retrieve the branch's HEAD, to then get the HEAD commit. | ||
ref, err := r.Head() | ||
CheckIfError(err) | ||
|
||
c, err := r.CommitObject(ref.Hash()) | ||
CheckIfError(err) | ||
|
||
Info("git blame %s", path) | ||
|
||
// Blame the given file/path. | ||
br, err := git.Blame(c, path) | ||
CheckIfError(err) | ||
|
||
fmt.Printf("%s", br.String()) | ||
} |
This file contains 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 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 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