github.com/qiniu/go-sdk/v7@v7.27.0/sandbox/git_options.go (about)

     1  package sandbox
     2  
     3  import "time"
     4  
     5  // GitOptions 是 git 命令执行的通用选项,可以被各 Options Struct 嵌入复用。
     6  type GitOptions struct {
     7  	// Envs 是额外的环境变量。SDK 会自动注入 GIT_TERMINAL_PROMPT=0 以禁止交互式提示。
     8  	Envs map[string]string
     9  	// User 指定执行命令的用户,缺省使用 DefaultUser。
    10  	User string
    11  	// Cwd 指定工作目录。
    12  	Cwd string
    13  	// Timeout 指定命令超时时间。
    14  	Timeout time.Duration
    15  }
    16  
    17  // CloneOptions 是 git clone 操作的选项。
    18  type CloneOptions struct {
    19  	GitOptions
    20  	// Path 指定克隆目标路径。
    21  	Path string
    22  	// Branch 指定要检出的分支,设置后会附加 --single-branch。
    23  	Branch string
    24  	// Depth 指定浅克隆深度。
    25  	Depth int
    26  	// Username 是 HTTPS 认证的用户名。
    27  	Username string
    28  	// Password 是 HTTPS 认证的密码或 token。
    29  	Password string
    30  	// DangerouslyStoreCredentials 为 true 时,凭证会持久化在 .git/config 中;
    31  	// 默认会在 clone 完成后通过 remote set-url 清除。
    32  	DangerouslyStoreCredentials bool
    33  }
    34  
    35  // InitOptions 是 git init 操作的选项。
    36  type InitOptions struct {
    37  	GitOptions
    38  	// Bare 为 true 时创建 bare 仓库。
    39  	Bare bool
    40  	// InitialBranch 指定初始分支名(例如 "main")。
    41  	InitialBranch string
    42  }
    43  
    44  // RemoteAddOptions 是 git remote add 操作的选项。
    45  type RemoteAddOptions struct {
    46  	GitOptions
    47  	// Fetch 为 true 时在添加 remote 后立即执行 fetch。
    48  	Fetch bool
    49  	// Overwrite 为 true 时,若 remote 已存在则覆盖其 URL。
    50  	Overwrite bool
    51  }
    52  
    53  // CommitOptions 是 git commit 操作的选项。
    54  type CommitOptions struct {
    55  	GitOptions
    56  	// AuthorName 覆盖提交作者名。
    57  	AuthorName string
    58  	// AuthorEmail 覆盖提交作者邮箱。
    59  	AuthorEmail string
    60  	// AllowEmpty 允许空提交。
    61  	AllowEmpty bool
    62  }
    63  
    64  // AddOptions 是 git add 操作的选项。
    65  type AddOptions struct {
    66  	GitOptions
    67  	// Files 指定要暂存的文件列表,为空时根据 All 决定使用 -A 或 "."。
    68  	Files []string
    69  	// All 控制 Files 为空时是否使用 -A 暂存所有变更。
    70  	// 为 nil 时默认 true(与 E2B 对齐);显式为 false 则使用 "." 仅暂存当前目录。
    71  	All *bool
    72  }
    73  
    74  // DeleteBranchOptions 是 git branch -d/-D 操作的选项。
    75  type DeleteBranchOptions struct {
    76  	GitOptions
    77  	// Force 为 true 时使用 -D 强制删除分支。
    78  	Force bool
    79  }
    80  
    81  // GitResetMode 是 git reset 的模式。
    82  type GitResetMode string
    83  
    84  const (
    85  	// GitResetModeSoft 对应 git reset --soft。
    86  	GitResetModeSoft GitResetMode = "soft"
    87  	// GitResetModeMixed 对应 git reset --mixed。
    88  	GitResetModeMixed GitResetMode = "mixed"
    89  	// GitResetModeHard 对应 git reset --hard。
    90  	GitResetModeHard GitResetMode = "hard"
    91  	// GitResetModeMerge 对应 git reset --merge。
    92  	GitResetModeMerge GitResetMode = "merge"
    93  	// GitResetModeKeep 对应 git reset --keep。
    94  	GitResetModeKeep GitResetMode = "keep"
    95  )
    96  
    97  // ResetOptions 是 git reset 操作的选项。
    98  type ResetOptions struct {
    99  	GitOptions
   100  	// Mode 是重置模式,缺省时不传 --<mode> 参数。
   101  	Mode GitResetMode
   102  	// Target 是要重置到的提交、分支或引用,缺省为 HEAD。
   103  	Target string
   104  	// Paths 是要重置的路径列表。
   105  	Paths []string
   106  }
   107  
   108  // RestoreOptions 是 git restore 操作的选项。
   109  // 当 Staged 与 Worktree 均未显式设置时,默认仅恢复工作区(Worktree=true)。
   110  type RestoreOptions struct {
   111  	GitOptions
   112  	// Paths 是要恢复的路径列表,至少一个。
   113  	Paths []string
   114  	// Staged 为非 nil 时显式控制是否恢复索引。
   115  	Staged *bool
   116  	// Worktree 为非 nil 时显式控制是否恢复工作区。
   117  	Worktree *bool
   118  	// Source 指定从该提交或引用恢复。
   119  	Source string
   120  }
   121  
   122  // PushOptions 是 git push 操作的选项。
   123  type PushOptions struct {
   124  	GitOptions
   125  	// Remote 指定远程名(例如 "origin")。
   126  	Remote string
   127  	// Branch 指定要推送的分支名。
   128  	Branch string
   129  	// SetUpstream 控制是否附加 --set-upstream。
   130  	// 为 nil 时按 SDK 默认(true,与 E2B 对齐);显式设置为 false 可关闭。
   131  	SetUpstream *bool
   132  	// Username 是 HTTPS 认证的用户名。
   133  	Username string
   134  	// Password 是 HTTPS 认证的密码或 token。
   135  	Password string
   136  }
   137  
   138  // PullOptions 是 git pull 操作的选项。
   139  type PullOptions struct {
   140  	GitOptions
   141  	// Remote 指定远程名。
   142  	Remote string
   143  	// Branch 指定要拉取的分支名。
   144  	Branch string
   145  	// Username 是 HTTPS 认证的用户名。
   146  	Username string
   147  	// Password 是 HTTPS 认证的密码或 token。
   148  	Password string
   149  }
   150  
   151  // ConfigOptions 是 git config 操作的选项。
   152  // Scope 为 "local" 时必须提供 Path。
   153  type ConfigOptions struct {
   154  	GitOptions
   155  	// Scope 是 git config 作用域,缺省为 GitConfigScopeGlobal。
   156  	Scope GitConfigScope
   157  	// Path 是仓库路径,仅在 Scope 为 GitConfigScopeLocal 时必填。
   158  	Path string
   159  }
   160  
   161  // AuthenticateOptions 是 DangerouslyAuthenticate 的选项。
   162  type AuthenticateOptions struct {
   163  	GitOptions
   164  	// Username 是 HTTPS 认证的用户名,必填。
   165  	Username string
   166  	// Password 是 HTTPS 认证的密码或 token,必填。
   167  	Password string
   168  	// Host 是要认证的主机,缺省为 "github.com"。
   169  	Host string
   170  	// Protocol 是要认证的协议,缺省为 "https"。
   171  	// 出于安全考虑只允许 "https",传入其他值会返回 InvalidArgumentError。
   172  	Protocol string
   173  }