git

package
v3.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthForURL

func AuthForURL(rawURL string) (transport.AuthMethod, error)

AuthForURL returns the credential to use when cloning the given URL, reading the token and host from viper. It is the CLI's single-token path; the web server uses TokenAuth with a per-user token instead.

The token authenticates against one host: the configured GitLab instance. Under SSH this was invisible — the operator's key worked against any host, so a starter repo or deferred branch could live on github.com or another GitLab. Over HTTPS with a PAT that no longer holds, and sending the GitLab token to a foreign host would leak it. So the token is attached only for the GitLab host; any other host is cloned unauthenticated, which works for public repositories and fails with a plain "authentication required" for private ones.

func Clone

func Clone(rep reporter.Reporter, cfg *config.AssignmentConfig)

Clone clones every student/group repository to disk. It is CLI-only — the web server never writes to a local working directory. --suppress passes a discard reporter so only the machine-readable paths are printed.

func GetAuth

func GetAuth() (transport.AuthMethod, error)

GetAuth returns the credential glabs uses to talk to its own GitLab instance: the personal access token, over HTTPS.

glabs used to authenticate git with an SSH key (`sshprivatekey`), separate from the token it already needed for the API. That is gone: one credential, one transport, the same in the CLI and — once it exists — the web server, where a per-user SSH key would be a shared identity with access to every user's repositories. The token needs the `write_repository` scope in addition to `api`.

GitLab accepts the token as the HTTP password with any non-empty username; "oauth2" is the conventional one.

func ProjectRepoUrl

func ProjectRepoUrl(cfg *config.AssignmentConfig, suffix string) string

ProjectRepoUrl is the HTTPS clone URL for a student's or group's repository. cfg.URL is already https://host/coursepath, so the repository URL is just that plus the repo name; glabs clones it over HTTPS with the token.

func Push

func Push(rep reporter.Reporter, assignmentCfg *config.AssignmentConfig, projectname string, sourceRepo *SourceRepo, toBranch string, force bool, project *gitlab.Project) error

Types

type Committer added in v3.30.0

type Committer struct {
	Name  string
	Email string
}

Committer identifies who authors the starter-code commit. Empty fields fall back to the glabs bot identity, so a caller that does not care (the common case) can pass the zero value. The web server passes the acting user.

type SourceRepo

type SourceRepo struct {
	Repo *git.Repository
	Ref  plumbing.ReferenceName
	Auth transport.AuthMethod
}

func PrepareSourceRepo

func PrepareSourceRepo(rep reporter.Reporter, auth TokenAuth, committer Committer, url, fromBranch string, singleCommit bool, commitMessage string) (*SourceRepo, error)

PrepareSourceRepo clones the starter code into memory and returns it ready to push. auth resolves the clone credential from an explicit host+token (no viper), and committer authors the squashed single commit — both injected so the web server can act as a specific user.

type TokenAuth added in v3.30.0

type TokenAuth struct {
	GitLabHost string
	Token      string
}

TokenAuth resolves git credentials from an explicit GitLab host and token, without touching viper — so the web server can authenticate git as a specific user (its per-user PAT), rather than through a single package-global token that cannot serve multiple users. It applies the same host rule as AuthForURL: the token is attached only to URLs on the GitLab host, never to a foreign one.

Jump to

Keyboard shortcuts

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