本文整理汇总了Golang中v/io/jiri/gitutil.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCLSync
// TestCLSync checks the operation of the "jiri cl sync" command.
func TestCLSync(t *testing.T) {
fake, _, _, _, cleanup := setupTest(t, true)
defer cleanup()
// Create some dependent CLs.
if err := newCL(fake.X, []string{"feature1"}); err != nil {
t.Fatalf("%v", err)
}
if err := newCL(fake.X, []string{"feature2"}); err != nil {
t.Fatalf("%v", err)
}
// Add the "test" file to the master.
if err := gitutil.New(fake.X.NewSeq()).CheckoutBranch("master"); err != nil {
t.Fatalf("%v", err)
}
commitFiles(t, fake.X, []string{"test"})
// Sync the dependent CLs.
if err := gitutil.New(fake.X.NewSeq()).CheckoutBranch("feature2"); err != nil {
t.Fatalf("%v", err)
}
if err := syncCL(fake.X); err != nil {
t.Fatalf("%v", err)
}
// Check that the "test" file exists in the dependent CLs.
for _, branch := range []string{"feature1", "feature2"} {
if err := gitutil.New(fake.X.NewSeq()).CheckoutBranch(branch); err != nil {
t.Fatalf("%v", err)
}
assertFilesExist(t, fake.X, []string{"test"})
}
}
示例2: TestCreateReviewBranch
// TestCreateReviewBranch checks that the temporary review branch is
// created correctly.
func TestCreateReviewBranch(t *testing.T) {
fake, _, _, _, cleanup := setupTest(t, true)
defer cleanup()
branch := "my-branch"
if err := gitutil.New(fake.X.NewSeq()).CreateAndCheckoutBranch(branch); err != nil {
t.Fatalf("%v", err)
}
files := []string{"file1", "file2", "file3"}
commitFiles(t, fake.X, files)
review, err := newReview(fake.X, project.Project{}, gerrit.CLOpts{})
if err != nil {
t.Fatalf("%v", err)
}
if expected, got := branch+"-REVIEW", review.reviewBranch; expected != got {
t.Fatalf("Unexpected review branch name: expected %v, got %v", expected, got)
}
commitMessage := "squashed commit"
if err := review.createReviewBranch(commitMessage); err != nil {
t.Fatalf("%v", err)
}
// Verify that the branch exists.
if !gitutil.New(fake.X.NewSeq()).BranchExists(review.reviewBranch) {
t.Fatalf("review branch not found")
}
if err := gitutil.New(fake.X.NewSeq()).CheckoutBranch(review.reviewBranch); err != nil {
t.Fatalf("%v", err)
}
assertCommitCount(t, fake.X, review.reviewBranch, "master", 1)
assertFilesCommitted(t, fake.X, files)
}
示例3: createRepoFromOrigin
// createRepoFromOrigin creates a Git repo tracking origin/master.
func createRepoFromOrigin(t *testing.T, jirix *jiri.X, subpath string, originPath string) string {
repoPath := createRepo(t, jirix, subpath)
chdir(t, jirix, repoPath)
if err := gitutil.New(jirix.NewSeq()).AddRemote("origin", originPath); err != nil {
t.Fatalf("%v", err)
}
if err := gitutil.New(jirix.NewSeq()).Pull("origin", "master"); err != nil {
t.Fatalf("%v", err)
}
return repoPath
}
示例4: EnableRemoteManifestPush
// EnableRemoteManifestPush enables pushes to the remote manifest
// repository.
func (fake FakeJiriRoot) EnableRemoteManifestPush() error {
dir := gitutil.RootDirOpt(filepath.Join(fake.remote, manifestProjectPath))
if !gitutil.New(fake.X.NewSeq(), dir).BranchExists("non-master") {
if err := gitutil.New(fake.X.NewSeq(), dir).CreateBranch("non-master"); err != nil {
return err
}
}
if err := gitutil.New(fake.X.NewSeq(), dir).CheckoutBranch("non-master"); err != nil {
return err
}
return nil
}
示例5: CreateRemoteProject
// CreateRemoteProject creates a new remote project.
func (fake FakeJiriRoot) CreateRemoteProject(name string) error {
projectDir := filepath.Join(fake.remote, name)
if err := fake.X.NewSeq().MkdirAll(projectDir, os.FileMode(0700)).Done(); err != nil {
return err
}
if err := gitutil.New(fake.X.NewSeq()).Init(projectDir); err != nil {
return err
}
if err := gitutil.New(fake.X.NewSeq(), gitutil.RootDirOpt(projectDir)).CommitWithMessage("initial commit"); err != nil {
return err
}
fake.Projects[name] = projectDir
return nil
}
示例6: defaultCommitMessage
// defaultCommitMessage creates the default commit message from the
// list of commits on the branch.
func (review *review) defaultCommitMessage() (string, error) {
commitMessages := ""
var err error
if commitMessageBodyFlag != "" {
msg, tmpErr := ioutil.ReadFile(commitMessageBodyFlag)
commitMessages = string(msg)
err = tmpErr
} else {
commitMessages, err = gitutil.New(review.jirix.NewSeq()).CommitMessages(review.CLOpts.Branch, review.reviewBranch)
}
if err != nil {
return "", err
}
// Strip "MultiPart ..." from the commit messages.
strippedMessages := multiPartRE.ReplaceAllLiteralString(commitMessages, "")
// Strip "Change-Id: ..." from the commit messages.
strippedMessages = changeIDRE.ReplaceAllLiteralString(strippedMessages, "")
// Add comment markers (#) to every line.
commentedMessages := "# " + strings.Replace(strippedMessages, "\n", "\n# ", -1)
message := defaultMessageHeader + commentedMessages
if multipart := review.readMultiPart(); multipart != "" {
message = message + "\n" + multipart + "\n"
}
return message, nil
}
示例7: DisableRemoteManifestPush
// DisableRemoteManifestPush disables pushes to the remote manifest
// repository.
func (fake FakeJiriRoot) DisableRemoteManifestPush() error {
dir := gitutil.RootDirOpt(filepath.Join(fake.remote, manifestProjectPath))
if err := gitutil.New(fake.X.NewSeq(), dir).CheckoutBranch("master"); err != nil {
return err
}
return nil
}
示例8: commitAndPushChanges
// commitAndPushChanges commits changes identified by the given manifest file
// and label to the containing repository and pushes these changes to the
// remote repository.
func commitAndPushChanges(jirix *jiri.X, snapshotDir, snapshotFile, label string) (e error) {
cwd, err := os.Getwd()
if err != nil {
return err
}
defer collect.Error(func() error { return jirix.NewSeq().Chdir(cwd).Done() }, &e)
if err := jirix.NewSeq().Chdir(snapshotDir).Done(); err != nil {
return err
}
relativeSnapshotPath := strings.TrimPrefix(snapshotFile, snapshotDir+string(os.PathSeparator))
git := gitutil.New(jirix.NewSeq())
// Pull from master so we are up-to-date.
if err := git.Pull("origin", "master"); err != nil {
return err
}
if err := git.Add(relativeSnapshotPath); err != nil {
return err
}
if err := git.Add(label); err != nil {
return err
}
name := strings.TrimPrefix(snapshotFile, snapshotDir)
if err := git.CommitNoVerify(fmt.Sprintf("adding snapshot %q for label %q", name, label)); err != nil {
return err
}
if err := git.Push("origin", "master", gitutil.VerifyOpt(false)); err != nil {
return err
}
return nil
}
示例9: getCommitMessageFileName
func getCommitMessageFileName(jirix *jiri.X, branch string) (string, error) {
topLevel, err := gitutil.New(jirix.NewSeq()).TopLevel()
if err != nil {
return "", err
}
return filepath.Join(topLevel, jiri.ProjectMetaDir, branch, commitMessageFileName), nil
}
示例10: 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(jirix *jiri.X) (e error) {
originalBranch, err := gitutil.New(jirix.NewSeq()).CurrentBranchName()
if err != nil {
return err
}
branches, err := getDependentCLs(jirix, originalBranch)
if err != nil {
return err
}
for i := 1; i < len(branches); i++ {
file, err := getCommitMessageFileName(jirix, branches[i])
if err != nil {
return err
}
if _, err := jirix.NewSeq().Stat(file); err != nil {
if !runutil.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
}
示例11: assertFilesNotCommitted
// assertFilesNotCommitted asserts that the files exist and are *not*
// committed in the current branch.
func assertFilesNotCommitted(t *testing.T, jirix *jiri.X, files []string) {
assertFilesExist(t, jirix, files)
for _, file := range files {
if gitutil.New(jirix.NewSeq()).IsFileCommitted(file) {
t.Fatalf("expected file %v not to be committed but it is", file)
}
}
}
示例12: assertFilesPushedToRef
// assertFilesPushedToRef asserts that the given files have been
// pushed to the given remote repository reference.
func assertFilesPushedToRef(t *testing.T, jirix *jiri.X, repoPath, gerritPath, pushedRef string, files []string) {
chdir(t, jirix, gerritPath)
assertCommitCount(t, jirix, pushedRef, "master", 1)
if err := gitutil.New(jirix.NewSeq()).CheckoutBranch(pushedRef); err != nil {
t.Fatalf("%v", err)
}
assertFilesCommitted(t, jirix, files)
chdir(t, jirix, repoPath)
}
示例13: assertStashSize
// assertStashSize asserts that the stash size matches the expected
// size.
func assertStashSize(t *testing.T, jirix *jiri.X, want int) {
got, err := gitutil.New(jirix.NewSeq()).StashSize()
if err != nil {
t.Fatalf("%v", err)
}
if got != want {
t.Fatalf("unxpected stash size: got %v, want %v", got, want)
}
}
示例14: assertCommitCount
// assertCommitCount asserts that the commit count between two
// branches matches the expectedCount.
func assertCommitCount(t *testing.T, jirix *jiri.X, branch, baseBranch string, expectedCount int) {
got, err := gitutil.New(jirix.NewSeq()).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)
}
}
示例15: commitFile
// commitFile commits a file with the specified content into a branch
func commitFile(t *testing.T, jirix *jiri.X, filename string, content string) {
s := jirix.NewSeq()
if err := s.WriteFile(filename, []byte(content), 0644).Done(); err != nil {
t.Fatalf("%v", err)
}
commitMessage := "Commit " + filename
if err := gitutil.New(jirix.NewSeq()).CommitFile(filename, commitMessage); err != nil {
t.Fatalf("%v", err)
}
}