本文整理汇总了Golang中v/io/jiri/tool.Context.Git方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Git方法的具体用法?Golang Context.Git怎么用?Golang Context.Git使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v/io/jiri/tool.Context
的用法示例。
在下文中一共展示了Context.Git方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkDependents
// checkDependents makes sure that all CLs in the sequence of
// dependent CLs leading to (but not including) the current branch
// have been exported to Gerrit.
func checkDependents(ctx *tool.Context) (e error) {
originalBranch, err := ctx.Git().CurrentBranchName()
if err != nil {
return err
}
branches, err := getDependentCLs(ctx, originalBranch)
if err != nil {
return err
}
for i := 1; i < len(branches); i++ {
file, err := getCommitMessageFileName(ctx, branches[i])
if err != nil {
return err
}
if _, err := ctx.Run().Stat(file); err != nil {
if !os.IsNotExist(err) {
return err
}
return fmt.Errorf(`Failed to export the branch %q to Gerrit because its ancestor %q has not been exported to Gerrit yet.
The following steps are needed before the operation can be retried:
$ git checkout %v
$ jiri cl mail
$ git checkout %v
# retry the original command
`, originalBranch, branches[i], branches[i], originalBranch)
}
}
return nil
}
示例2: reportNonMaster
// reportNonMaster checks if the given project is on master branch and
// if not, reports this fact along with information on how to update it.
func reportNonMaster(ctx *tool.Context, project Project) (e error) {
cwd, err := os.Getwd()
if err != nil {
return err
}
defer collect.Error(func() error { return ctx.Run().Chdir(cwd) }, &e)
if err := ctx.Run().Chdir(project.Path); err != nil {
return err
}
switch project.Protocol {
case "git":
current, err := ctx.Git().CurrentBranchName()
if err != nil {
return err
}
if current != "master" {
line1 := fmt.Sprintf(`NOTE: "jiri update" only updates the "master" branch and the current branch is %q`, current)
line2 := fmt.Sprintf(`to update the %q branch once the master branch is updated, run "git merge master"`, current)
opts := runutil.Opts{Verbose: true}
ctx.Run().OutputWithOpts(opts, []string{line1, line2})
}
return nil
default:
return UnsupportedProtocolErr(project.Protocol)
}
}
示例3: getDependencyPathFileName
func getDependencyPathFileName(ctx *tool.Context, branch string) (string, error) {
topLevel, err := ctx.Git().TopLevel()
if err != nil {
return "", err
}
return filepath.Join(topLevel, project.MetadataDirName(), branch, dependencyPathFileName), nil
}
示例4: setProjectRevisions
// setProjectRevisions sets the current project revision from the master for
// each project as found on the filesystem
func setProjectRevisions(ctx *tool.Context, projects Projects) (_ Projects, e error) {
cwd, err := os.Getwd()
if err != nil {
return nil, err
}
defer collect.Error(func() error { return ctx.Run().Chdir(cwd) }, &e)
for name, project := range projects {
switch project.Protocol {
case "git":
if err := ctx.Run().Chdir(project.Path); err != nil {
return nil, err
}
revision, err := ctx.Git().CurrentRevisionOfBranch("master")
if err != nil {
return nil, err
}
project.Revision = revision
default:
return nil, UnsupportedProtocolErr(project.Protocol)
}
projects[name] = project
}
return projects, nil
}
示例5: DisableRemoteManifestPush
// DisableRemoteManifestPush disables pushes to the remote manifest
// repository.
func (root FakeJiriRoot) DisableRemoteManifestPush(ctx *tool.Context) error {
dir := tool.RootDirOpt(filepath.Join(root.remote, manifestProject))
if err := ctx.Git(dir).CheckoutBranch("master"); err != nil {
return err
}
return nil
}
示例6: assertFilesNotCommitted
// assertFilesNotCommitted asserts that the files exist and are *not*
// committed in the current branch.
func assertFilesNotCommitted(t *testing.T, ctx *tool.Context, files []string) {
assertFilesExist(t, ctx, files)
for _, file := range files {
if ctx.Git().IsFileCommitted(file) {
t.Fatalf("expected file %v not to be committed but it is", file)
}
}
}
示例7: assertStashSize
// assertStashSize asserts that the stash size matches the expected
// size.
func assertStashSize(t *testing.T, ctx *tool.Context, want int) {
got, err := ctx.Git().StashSize()
if err != nil {
t.Fatalf("%v", err)
}
if got != want {
t.Fatalf("unxpected stash size: got %v, want %v", got, want)
}
}
示例8: assertFilesPushedToRef
// assertFilesPushedToRef asserts that the given files have been
// pushed to the given remote repository reference.
func assertFilesPushedToRef(t *testing.T, ctx *tool.Context, repoPath, gerritPath, pushedRef string, files []string) {
chdir(t, ctx, gerritPath)
assertCommitCount(t, ctx, pushedRef, "master", 1)
if err := ctx.Git().CheckoutBranch(pushedRef); err != nil {
t.Fatalf("%v", err)
}
assertFilesCommitted(t, ctx, files)
chdir(t, ctx, repoPath)
}
示例9: assertCommitCount
// assertCommitCount asserts that the commit count between two
// branches matches the expectedCount.
func assertCommitCount(t *testing.T, ctx *tool.Context, branch, baseBranch string, expectedCount int) {
got, err := ctx.Git().CountCommits(branch, baseBranch)
if err != nil {
t.Fatalf("%v", err)
}
if want := 1; got != want {
t.Fatalf("unexpected number of commits: got %v, want %v", got, want)
}
}
示例10: commitFile
// commitFile commits a file with the specified content into a branch
func commitFile(t *testing.T, ctx *tool.Context, filename string, content string) {
if err := ctx.Run().WriteFile(filename, []byte(content), 0644); err != nil {
t.Fatalf("%v", err)
}
commitMessage := "Commit " + filename
if err := ctx.Git().CommitFile(filename, commitMessage); err != nil {
t.Fatalf("%v", err)
}
}
示例11: createRepoFromOrigin
// createRepoFromOrigin creates a Git repo tracking origin/master.
func createRepoFromOrigin(t *testing.T, ctx *tool.Context, workingDir string, subpath string, originPath string) string {
repoPath := createRepo(t, ctx, workingDir, subpath)
chdir(t, ctx, repoPath)
if err := ctx.Git().AddRemote("origin", originPath); err != nil {
t.Fatalf("%v", err)
}
if err := ctx.Git().Pull("origin", "master"); err != nil {
t.Fatalf("%v", err)
}
return repoPath
}
示例12: submit
// submit mocks a Gerrit review submit by pushing the Gerrit remote to origin.
// Actually origin pulls from Gerrit since origin isn't actually a bare git repo.
// Some of our tests actually rely on accessing .git in origin, so it must be non-bare.
func submit(t *testing.T, ctx *tool.Context, originPath string, gerritPath string, review *review) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("Getwd() failed: %v", err)
}
chdir(t, ctx, originPath)
expectedRef := gerrit.Reference(review.CLOpts)
if err := ctx.Git().Pull(gerritPath, expectedRef); err != nil {
t.Fatalf("Pull gerrit to origin failed: %v", err)
}
chdir(t, ctx, cwd)
}
示例13: resetToOriginMaster
func resetToOriginMaster(t *testing.T, ctx *tool.Context, projectDir string) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("%v", err)
}
defer ctx.Run().Chdir(cwd)
if err := ctx.Run().Chdir(projectDir); err != nil {
t.Fatalf("%v", err)
}
if err := ctx.Git().Reset("origin/master"); err != nil {
t.Fatalf("%v", err)
}
}
示例14: createAndCheckoutBranch
func createAndCheckoutBranch(t *testing.T, ctx *tool.Context, projectDir, branch string) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("%v", err)
}
defer ctx.Run().Chdir(cwd)
if err := ctx.Run().Chdir(projectDir); err != nil {
t.Fatalf("%v", err)
}
if err := ctx.Git().CreateAndCheckoutBranch(branch); err != nil {
t.Fatalf("%v", err)
}
}
示例15: addRemote
func addRemote(t *testing.T, ctx *tool.Context, localProject, name, remoteProject string) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("%v", err)
}
defer ctx.Run().Chdir(cwd)
if err := ctx.Run().Chdir(localProject); err != nil {
t.Fatalf("%v", err)
}
if err := ctx.Git().AddRemote(name, remoteProject); err != nil {
t.Fatalf("%v", err)
}
}