yakgit

package
v1.3.5-alpha-0814 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

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,

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

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

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

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

Functions

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 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 NewConfig

func NewConfig() *config

func SetProxy

func SetProxy(proxies ...string)

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

Types

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 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 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