yakgit

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 43 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEFAULT_GIT_FILES = []string{

		".git/COMMIT_EDITMSG",
		".git/description",
		".git/info/exclude",
		".git/FETCH_HEAD",
		".git/logs/refs/remotes/origin/HEAD",
		".git/ORIG_HEAD",
		".git/packed-refs",
		".git/logs/refs/stash",
		".git/refs/remotes/origin/HEAD",
		".git/objects/info/alternates",
		".git/objects/info/http-alternates",
		".git/refs/tags/v0.0.1",
		".git/refs/tags/0.0.1",
		".git/refs/tags/v1.0.0",
		".git/refs/tags/1.0.0",
	}
	DEFAULT_GIT_FILES_DANGEROUS = []string{
		".git/config",
		".git/hooks/applypatch-msg",
		".git/hooks/commit-msg",
		".git/hooks/fsmonitor-watchman",
		".git/hooks/post-update",
		".git/hooks/pre-applypatch",
		".git/hooks/pre-commit",
		".git/hooks/pre-merge-commit",
		".git/hooks/pre-push",
		".git/hooks/pre-rebase",
		".git/hooks/pre-receive",
		".git/hooks/prepare-commit-msg",
		".git/hooks/update",
	}

	COMMON_BRANCH_NAMES = []string{
		"daily",
		"dev",
		"feature",
		"feat",
		"fix",
		"hotfix",
		"issue",
		"main",
		"master",
		"ng",
		"quickfix",
		"release",
		"test",
		"testing",
		"wip",
	}

	EXPAND_BRANCH_NAME_PATH = []string{
		".git/logs/refs/heads",
		".git/logs/refs/remotes/origin",
		".git/refs/remotes/origin",
		".git/refs/heads",
	}

	HEAD_REGEX      = regexp.MustCompile("ref: refs/heads/([a-zA-Z0-9_-]+)")
	LOGs_HEAD_REGEX = regexp.MustCompile("checkout: moving from ([a-zA-Z0-9_-]+) to ([a-zA-Z0-9_-]+)")
	HASH_REGEX      = regexp.MustCompile("[a-f0-9]{40}")
	PACK_REGEX      = regexp.MustCompile("P pack-([a-z0-9]{40}).pack")
)
View Source
var Exports = map[string]any{
	"SetProxy": SetProxy,

	"RevParse":        RevParse,
	"HeadHash":        GetHeadHash,
	"HeadBranch":      GetHeadBranch,
	"HeadBranchRange": GetBranchRange,
	"ParentHash":      GetParentCommitHash,
	"Glance":          Glance,
	"Branch":          GetAllBranches,
	"Blame":           Blame,
	"BlameCommit":     BlameWithCommit,

	"GitHack":       GitHack,
	"Clone":         Clone,
	"Pull":          pull,
	"Fetch":         fetch,
	"Checkout":      checkout,
	"IterateCommit": EveryCommit,

	"FileSystemFromCommit":          FromCommit,
	"FileSystemFromCommits":         FromCommits,
	"FileSystemFromCommitRange":     FromCommitRange,
	"FileSystemFromCommitDateRange": FileSystemFromCommitDateRange,
	"FileSystemCurrentWeek":         FileSystemCurrentWeek,
	"FileSystemLastSevenDay":        FileSystemLastSevenDay,
	"FileSystemCurrentDay":          FileSystemCurrentDay,
	"FileSystemCurrentMonth":        FileSystemCurrentMonth,
	"FileSystemFromDate":            FileSystemFromDate,
	"FileSystemFromMonth":           FileSystemFromMonth,

	"auth":           WithUsernamePassword,
	"context":        WithContext,
	"depth":          WithDepth,
	"recursive":      WithRecuriveSubmodule,
	"remote":         WithRemote,
	"force":          WithForce,
	"verify":         WithVerifyTLS,
	"checkoutCreate": WithCheckoutCreate,
	"checkoutForce":  WithCheckoutForce,
	"checkoutKeep":   WithCheckoutKeep,
	"noFetchTags":    WithNoFetchTags,
	"fetchAllTags":   WithFetchAllTags,
	"branch":         WithBranch,

	"handleCommit":    WithHandleGitCommit,
	"filterCommit":    WithFilterGitCommit,
	"handleReference": WithHandleGitReference,
	"filterReference": WithFilterGitReference,

	"threads":           WithThreads,
	"useLocalGitBinary": WithUseLocalGitBinary,
	"httpOpts":          WithHTTPOptions,
}

Functions

func Clone

func Clone(u string, localPath string, opt ...Option) error

Clone 用于克隆远程仓库并存储到本地路径中,它还可以接收零个到多个选项函数,用于影响克隆行为 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.recursive(true), git.verify(false)) ```

func EveryCommit

func EveryCommit(localRepos string, opt ...Option) error

IterateCommit 用于指定一个本地仓库,遍历其所有的提交记录(commit),并对过滤后的每个提交记录执行指定的操作,它还可以接收零个到多个选项函数,用于配置回调函数 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,过滤作者名字为xxx的提交记录,打印剩余的每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.filterCommit((c) => { return c.Author.Name != "xxx" }), git.handleCommit((c) => { println(c.String()) })) ```

func FileSystemCurrentDay

func FileSystemCurrentDay(repos string) (filesys_interface.FileSystem, error)

FileSystemCurrentDay 获取当前自然日的文件系统

func FileSystemCurrentMonth

func FileSystemCurrentMonth(repos string) (filesys_interface.FileSystem, error)

FileSystemCurrentMonth 获取当前自然月的文件系统

func FileSystemCurrentWeek

func FileSystemCurrentWeek(repos string) (filesys_interface.FileSystem, error)

FileSystemCurrentWeek 获取当前自然周(周一到周天)的文件系统

func FileSystemFromCommitDateRange

func FileSystemFromCommitDateRange(repos string, startDate, endDate any) (filesys_interface.FileSystem, error)

FileSystemFromCommitDateRange 根据日期范围获取文件系统 startDate: 起始日期,支持多种格式和类型 endDate: 结束日期,支持多种格式和类型

func FileSystemFromDate

func FileSystemFromDate(repos string, date any) (filesys_interface.FileSystem, error)

FileSystemFromDate 根据指定日期获取该日的文件系统

func FileSystemFromMonth

func FileSystemFromMonth(repos string, year int, month int) (filesys_interface.FileSystem, error)

FileSystemFromMonth 根据指定年月获取该月的文件系统

func FileSystemLastSevenDay

func FileSystemLastSevenDay(repos string) (filesys_interface.FileSystem, error)

FileSystemLastSevenDay 获取最近七天的文件系统

func FromCommit

func FromCommit(repos string, commitHash string) (filesys_interface.FileSystem, error)

FileSystemFromCommit 从指定的commit中获取文件系统

Example: ``` fs := git.FileSystemFromCommit("path/to/repo", "2871a988b2ed7ec10a1fd45eca248a96a99a8560")~ fs, err := git.FileSystemFromCommit("path/to/repo", "2871a988b2ed7ec10a1fd45eca248a96a99a8560") ```

func FromCommitRange

func FromCommitRange(repos string, start, end string) (*filesys.VirtualFS, error)

FileSystemFromCommitRange 从commit范围中获取文件系统

Example: ``` fs := git.FileSystemFromCommitRange("path/to/repo", "2871a988b2ed7ec10a1fd45eca248a96a99a8560", "54165a396a219d085980dca623ae1ff6582033ad")~ ```

func FromCommits

func FromCommits(repos string, commitHashes ...string) (filesys_interface.FileSystem, error)

FileSystemFromCommits 从多个commit中获取文件系统

Example: ``` fs := git.FileSystemFromCommits("path/to/repo", "2871a988b2ed7ec10a1fd45eca248a96a99a8560", "54165a396a219d085980dca623ae1ff6582033ad")~ fs, err := git.FileSystemFromCommits("path/to/repo", "54165a396a219d085980dca623ae1ff6582033ad", "2871a988b2ed7ec10a1fd45eca248a96a99a8560") ```

func GeneratorGitHTTPHandler

func GeneratorGitHTTPHandler(routePrefix, zipfileName string, zipRaw []byte) (string, func(http.ResponseWriter, *http.Request))

* use zipfile and routPrefix should be same * zipRaw should be zip `.git` folder * zipfileName should be the name of the zip file

func GetAllBranches

func GetAllBranches(repos string) ([]string, error)

func GetBranchRange

func GetBranchRange(repos string, branchName string) (start, end string, err error)

func GetCommitHashEx

func GetCommitHashEx(repo *git.Repository, hash string) (*object.Commit, error)

GetCommitHashEx 获取完整的commit hash 如果hash不是完整的commit hash,则尝试查找匹配的commit hash

func GetHeadBranch

func GetHeadBranch(repos string) string

func GetHeadHash

func GetHeadHash(repos string) string

func GetParentCommitHash

func GetParentCommitHash(repos string, commit string) (string, error)

func GitHack added in v1.2.8

func GitHack(remoteRepoURL string, localPath string, opts ...Option) (finalErr error)

GitHack 是一个用于利用 Git 源码泄露漏洞的函数 Git源码泄露漏洞是指:由于网站服务器的错误配置,可以通过 HTTP / HTTPS 直接访问到网站 .git 目录下的文件,从而导致源码泄露 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.threads(8)) ```

func GitOpenRepositoryWithCache

func GitOpenRepositoryWithCache(localPath string) (*git.Repository, error)

func Glance

func Glance(repos string) string

func NewConfig

func NewConfig() *config

func RevParse

func RevParse(repos string, rev string) (string, error)

func SetProxy

func SetProxy(proxies ...string)

SetProxy 是一个辅助函数,用于指定其他 Git 操作(例如Clone)的代理 Example: ``` git.SetProxy("http://127.0.0.1:1080") ```

func ShortHashToFullHash

func ShortHashToFullHash(repo *git.Repository, hash string) (string, error)

Types

type BlameLine

type BlameLine struct {
	LineNumber int
	*git.Line
}

func (*BlameLine) String

func (b *BlameLine) String() string

type BlameLines

type BlameLines []*BlameLine

func Blame

func Blame(repos string, fileName string) (BlameLines, error)

func BlameWithCommit

func BlameWithCommit(repos string, fileName string, rev string) (BlameLines, error)

func (BlameLines) String

func (b BlameLines) String() string

type GitHackObject added in v1.2.8

type GitHackObject struct {
	// contains filtered or unexported fields
}

func NewGitHackObject added in v1.2.8

func NewGitHackObject(remoteRepoURL, tempDirPath string, gitConfig *config) *GitHackObject

type Option

type Option func(*config) error

func WithBranch

func WithBranch(branch string) Option

func WithCheckoutCreate

func WithCheckoutCreate(b bool) Option

fetchAllTags 是一个选项函数,用于指定检出(checkout)操作时是否创建新分支 Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "feat/new-branch", git.checkoutCreate(true)) ```

func WithCheckoutForce

func WithCheckoutForce(b bool) Option

fetchAllTags 是一个选项函数,用于指定检出(checkout)操作时是否强制 Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "old-branch", git.checkoutForce(true)) ```

func WithCheckoutKeep

func WithCheckoutKeep(b bool) Option

checkoutKeep 是一个选项函数,用于指定检出(checkout)操作时,本地更改(索引或工作树更改)是否被保留,如果保留,就可以将它们提交到目标分支,默认为false Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "old-branch", git.checkoutKeep(true)) ```

func WithContext

func WithContext(ctx context.Context) Option

context 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的上下文 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.context(context.New())) ```

func WithDepth

func WithDepth(depth int) Option

depth 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的最大深度,默认为1 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.Depth(1)) ```

func WithFetchAllTags

func WithFetchAllTags(b bool) Option

fetchAllTags 是一个选项函数,用于指定获取(fetch)操作时是否拉取所有标签 Example: ``` git.Fetch("C:/Users/xxx/Desktop/yaklang", git.fetchAllTags(true)) // 拉取所有标签 ```

func WithFilterGitCommit

func WithFilterGitCommit(f func(r *object.Commit) bool) Option

filterCommit 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为提交记录结构体(commit),每次遍历到提交记录时,就会调用这个回调函数,这个函数还有一个返回值,通过这个返回值来决定是否过滤掉这个提交记录 Example: ``` // 遍历提交记录,过滤作者名字为xxx的提交记录,打印剩余的每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterCommit((c) => { return c.Author.Name != "xxx" }), git.handleCommit((c) => { println(c.String()) })) ```

func WithFilterGitReference

func WithFilterGitReference(f func(r *plumbing.Reference) bool) Option

filterReference 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为引用记录结构体(reference),每次遍历到引用时,就会调用这个回调函数,这个函数还有一个返回值,通过这个返回值来决定是否过滤掉这个引用 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,打印剩余的每个引用记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.handleReference((ref) => { println(ref.String()) })) ```

func WithForce

func WithForce(b bool) Option

force 是一个选项函数,用于指定其他 Git 操作(例如Pull)时是否强制执行,默认为false Example: ``` git.Pull("C:/Users/xxx/Desktop/yaklang", git.verify(false), git.force(true)) ```

func WithHTTPOptions added in v1.2.8

func WithHTTPOptions(opts ...poc.PocConfigOption) Option

httpOpts 是一个GitHack选项函数,用于指定GitHack的HTTP选项,其接收零个到多个poc的请求选项函数 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.httpOpts(poc.timeout(10), poc.https(true))) ```

func WithHandleGitCommit

func WithHandleGitCommit(f func(r *object.Commit) error) Option

handleCommit 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为提交记录结构体(commit),每次遍历到一个过滤后的提交记录时,就会调用这个回调函数 Example: ``` // 遍历提交记录,打印每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.handleCommit((c) => { println(c.String()) })) ```

func WithHandleGitReference

func WithHandleGitReference(f func(r *plumbing.Reference) error) Option

handleReference 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为引用记录结构体(reference),每次遍历到过滤后的引用时,就会调用这个回调函数 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,打印剩余的每个引用记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.handleReference((ref) => { println(ref.String()) })) ```

func WithNoFetchTags

func WithNoFetchTags(b bool) Option

noFetchTags 是一个选项函数,用于指定获取(fetch)操作时是否不拉取标签 Example: ``` git.Fetch("C:/Users/xxx/Desktop/yaklang", git.noFetchTags(true)) // 不拉取标签 ```

func WithPrivateKey

func WithPrivateKey(userName, keyPath, password string) Option

func WithProxy

func WithProxy(proxyUrl, proxyName, proxyPasswd string) Option

func WithRecuriveSubmodule

func WithRecuriveSubmodule(b bool) Option

recursive 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的是否递归克隆子模块,默认为false Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.recursive(true)) ```

func WithRemote

func WithRemote(remote string) Option

remote 是一个选项函数,用于指定其他 Git 操作(例如Pull)时的远程仓库名称,默认为origin Example: ``` git.Pull("C:/Users/xxx/Desktop/yaklang", git.verify(false), git.remote("origin")) ```

func WithThreads added in v1.2.8

func WithThreads(threads int) Option

threads 是一个GitHack选项函数,用于指定并发数,默认为8 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.threads(8)) ```

func WithUseLocalGitBinary added in v1.2.8

func WithUseLocalGitBinary(b bool) Option

useLocalGitBinary 是一个GitHack选项函数,用于指定是否使用本地环境变量的git二进制文件来执行`git fsck`命令,这个命令用于尽可能恢复完整的git仓库,默认为true Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.useLocalGitBinary(true)) ```

func WithUsernamePassword

func WithUsernamePassword(username, password string) Option

auth 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的认证用户名和密码 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.auth("admin", "admin")) ```

func WithVerifyTLS

func WithVerifyTLS(b bool) Option

verify 是一个选项函数,用于指定其他 Git 操作(例如Clone)时是否验证TLS证书 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.recursive(true), git.verify(false)) ```

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL