jiri

package module
v0.0.0-...-abfb8b1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: BSD-3-Clause Imports: 8 Imported by: 157

README

Jiri

"Jiri integrates repositories intelligently"

Jiri is a tool for multi-repo development. It supports:

  • syncing multiple local repos with upstream,
  • capturing the current state of all local repos in a "snapshot",
  • restoring local project state from a snapshot, and
  • facilitating sending change lists to Gerrit.

Jiri has an extensible plugin model, making it easy to create new sub-commands.

Jiri is open-source. See the contributor guidelines here.

Jiri Basics

Jiri organizes a set of repositories on your local filesystem according to a manifest. These repositories are referred to as "projects", and are all contained within a single directory called the "jiri root" which is assumed to be set in the JIRI_ROOT environment variable.

The manifest file specifies the relative location of each project within the jiri root, and also includes other metadata about the project such as its remote url, the remote branch it should track, and more.

The jiri update command syncs the master branch of all local projects to the revision and remote branch specified in the manifest for each project. Jiri will create the project locally if it does not exist, and if run with the -gc flag, jiri will "garbage collect" any projects that are not listed in the manifest by deleting them locally.

The .jiri_manifest file in the jiri root describes which project jiri should sync. Typically the .jiri_manifest file will import other manifests, but it can also contain a list of projects.

For example, here is a simple .jiri_manifest with just two projects, "foo" and "bar", which are hosted on github and bitbucket respectively.

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <projects>
    <project name="foo-project"
             remote="https://github.com/my-org/foo"
             path="foo"/>
    <project name="bar"
             remote="https://bitbucket.com/other-org/bar"
             path="bar"/>
  </projects>
</manifest>

When you run jiri update for the first time, the "foo" and "bar" repos will be cloned into $JIRI_ROOT/foo and $JIRI_ROOT/bar respectively. Running jiri update again will sync the master branch of these repos with the remote master branch.

Note that the project paths do not need to be immediate children of the jiri root. We could have decided to set the path attribute for the "bar" project to "third_party/bar", or even nest "bar" inside the "foo" project by setting the path to "foo/bar" (assuming no files in the foo repo conflict with bar).

Because manifest files also need to be kept in sync between various team members, it often makes sense to keep your team's manifests in a version controlled repository.

Jiri makes it easy to "import" a remote manifest from your local .jiri_manifest file with the jiri import command. For example, running the following command will create a .jiri_manifest file (or append to an existing one) with an import tag that imports the minimal manifest from the https://github.com/vanadium/manifest repo.

jiri import -name="manifest" minimal https://github.com/vanadium/manifest

The next time you run jiri update, jiri will sync all projects listed in the Vanadium minimal manifest.

Quickstart

This section explains how to get started with jiri.

First we "bootstrap" jiri so that it can sync and build itself.

Then we create and import a new manifest, which specifies how jiri should manage your projects.

Bootstrapping

You can get jiri up-and-running in no time with the help of the bootstrap script.

First, pick a jiri root directory. All projects will be synced to subdirectories of the root.

export MY_ROOT=$HOME/myroot

Execute the jiri_bootstrap script, which will fetch and build the jiri tool, and initialize the root directory.

curl -s
https://raw.githubusercontent.com/vanadium/go.jiri/master/scripts/bootstrap_jiri | bash -s "$MY_ROOT"

The jiri command line tool will be installed in $MY_ROOT/.jiri_root/scripts/jiri, so add that to your PATH.

export PATH="$MY_ROOT"/.jiri_root/scripts:$PATH

Next, use the jiri import command to import the "minimal" manifest from the vanadium manifest repo. This manifest includes only the projects needed to build the jiri tool itself.

You can see the minimal manifest here. For more information on manifests, read the manifest docs.

cd "$MY_ROOT"
jiri import -name=manifest minimal https://vanadium.googlesource.com/manifest

You should now have a file in the root directory called .jiri_manifest, which will contain a single import.

Finally, run jiri update, which will sync all local projects to the revisions listed in the manifest (which in this case will be HEAD).

jiri update

You should now see the jiri project and dependencies in $MY_ROOT/release/go/src/v.io, and the vanadium manifest repo in $MY_ROOT/manifest.

Running jiri update again will sync the local repos to the remotes, and rebuild the jiri tool.

Managing your projects with jiri

Now that jiri is able to sync and build itself, we must tell it how to manage your projects.

In order for jiri to manage a set of projects, those projects must be listed in a manifest, and that manifest must be hosted in a git repo.

If you already have a manifest hosted in a git repo, you can import that manifest the same way we imported the "minimal" manifest.

For example, if your manifest is called "my_manifest" and is in a repo hosted at "https://github.com/my_org/manifests", then you can import that manifest as follows.

jiri import my_manifest https://github.com/my_org/manifests

The rest of this section walks through how to create a manifest from scratch, host it from a local git repo, and get jiri to manage it.

Suppose that the project you want jiri to manage is the "Hello-World" repo located at https://github.com/Test-Octowin/Hello-World.

First we'll create a new git repo to host the manifest we'll be writing.

mkdir -p /tmp/my_manifest_repo
cd /tmp/my_manifest_repo
git init

Next we'll create a manifest and commit it to the manifest repo.

The manifest file will include the Hello-World repo as well as the manifest repo itself.

cat <<EOF > my_manifest
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <projects>
    <project name="Hello-World"
             remote="https://github.com/Test-Octowin/Hello-World"
             path="helloworld"/>
    <project name="manifest"
             remote="/tmp/my_manifest_repo"
             path="manifest"/>
  </projects>
</manifest>
EOF

git add my_manifest
git commit -m "Add my_manifest."

This manifest contains a single project with the name "Hello-World" and the remote of the repo. The path attribute tells jiri to sync this repo inside the helloworld directory.

Normally we would want to push this repo to some remote to make it accessible to other users who want to sync the same projects. For now, however, we'll just refer to the repo by its path in the local filesystem.

Now we just need to import that new manifest and jiri update. Since we don't want the new manifest repo to conflict with the minimal manifest repo, we must pass the -path flag to the import statement.

cd "$MY_ROOT"
jiri import -path="my_manifest_repo" my_manifest /tmp/my_manifest_repo
jiri update

You should now see the Hello-World repo in $MY_ROOT/helloworld, and your manifest repo in $MY_ROOT/my_manifest_repo.

Command-line help

The jiri help command will print help documentation about the jiri tool and its subcommands.

For general documentation, including a list of subcommands, run jiri help. To find documentation about a specific topic or subcommand, run jiri help <command>.

You can read all the command-line documentation in a single page here: http://godoc.org/v.io/jiri.

Filesystem

See the jiri filesystem godocs.

Manifests

See the jiri manifest godocs.

Snapshots

TODO(nlacasse): Write me.

Profiles

TODO(nlacasse): Write me.

Gerrit CL workflow

Gerrit is a collaborative code-review tool used by many open source projects.

One of the peculiarities of Gerrit is that it expects a changelist to be represented by a single commit. This constrains the way developers may use git to work on their changes. In particular, they must use the --amend flag with all but the first git commit operation and they need to use git rebase to sync their pending code change with the remote master. See Android's repo command reference or Go's contributing instructions for examples of how intricate the workflow for resolving conflicts between the pending code change and the remote master is.

The jiri cl command enables interaction with Gerrit without having to use such a complex and error-prone workflow. With jiri cl, users commit as often as they want on feature branches, and jiri cl handles the hard work of squashing all commits into a single commit and sending to Gerrit.

The rest of this section describes common development operations using jiri cl. The term "CL" (short for "ChangeList") refers to a set of code changes uploaded for review.

Using feature branches

The "master" branch of each local repository is reserved for tracking its remote counterpart. All development should take place on a non-master "feature" branch. Once the code is reviewed and approved, it is merged into the remote master via the Gerrit code review system. The change can then be merged into the local master branch with jiri update.

Creating a new CL
  1. Sync the master branch with the remote.
jiri update
  1. Create a new feature branch for the CL.
jiri cl new <branch-name>
  1. Make modifications to the project source code.
  2. Stage any changed files for commit.
git add <file1> <file2> ... <fileN>
  1. Commit the changes.
git commit
  1. Repeat steps 3-5 as necessary.
Syncing a CL with the remote
  1. Sync the master branch with the remote.
jiri update
  1. Switch to the feature branch that corresponds to the CL under development.
git checkout <branch-name>
  1. Sync the feature branch with the master branch.
jiri cl sync
  1. If there are no conflicts between the master and the feature branch, the CL has been successfully synced with the remote.
  2. If there are conflicts:
  3. Manually resolve the conflicts.
  4. Stage any changed files for a commit. git add <file1> <file2> ... <fileN>
  5. Commit the changes. git commit
Requesting a code review
  1. Switch to the feature branch that corresponds to the CL under development.
git checkout <branch-name>
  1. Upload the CL to Gerrit.
jiri cl mail

If the CL upload is successful, this will print the URL of the CL hosted on Gerrit. You can add reviewers and comments through the Gerrit web UI at that URL.

Note that there are many useful flags for jiri cl. You can learn about them by running jiri cl --help.

Reviewing a CL
  1. Follow the link received in the code review email request.
  2. Use the Gerrit web UI to comment on the CL and click the "Reply" button to submit comments, selecting the appropriate code-review score.
Addressing review comments
  1. Switch to the feature branch that corresponds to the CL under development.
git checkout <branch-name>
  1. Modify and commit the code as described above.
  2. Reply to each Gerrit comment and click the "Reply" button to send them.
  3. Send the updated CL to Gerrit.
jiri cl mail
Submitting a CL
  1. Note that if the CL conflicts with any changes that have been submitted since the last update of the CL, these conflicts need to be resolved before the CL can be submitted. To do so, follow the steps in the "Syncing a CL with the remote" section above and then upload the updated CL to Gerrit.
jiri cl mail
  1. Once a CL meets the conditions for being submitted, it can be merged into the remote master branch by clicking the "Submit" button on the Gerrit web UI.
  2. Delete the local feature branch after the CL has been submitted to Gerrit.
  3. Sync the master branch to the laster version of the remote. jiri update
  4. Safely delete the feature branch that corresponds to the CL. jiri cl cleanup <branch-name>

Note that deleting the feature branch with git branch -d <branch-name> won't work in general because the git history on the local feature branch differs from the history on the remote master. The local feature branch might have many small commits, while the remote will have the same changes squashed into a single commit. This difference in the history will prevent git from letting you do git branch -d <branch-name>. You can use git branch -D <branch-name>, but that can potentially cause you to lose work if the branch has not been merged into master yet. For this reason, we recommend using jiri cl cleanup to delete the feature branch safely.

Dependent CLs

If you have changes A and B, and B depends on A, you can still submit distinct CLs for A and B that can be reviewed and submitted independently (although A must be submitted before B).

First, create your feature branch for A, make your change, and upload the CL for review according to the instructions above.

Then, while still on the feature branch for A, create your feature branch for B.

jiri cl new feature-B

Then make your change and upload the CL for review according to the instructions above.

You can respond to review comments by submitting new patch sets as normal.

After the CL for A has been submitted, make sure to clean up A's feature branch and upload a new patch set for feature B.

jiri update # fetch update that includes feature A
git checkout feature-B
jiri cl cleanup feature-A
git merge master # merge feature A into feature B branch
jiri cl mail # send new patch set for feature B

The CL for feature B can now be submitted.

This process can be extended for more than 2 CLs. You must keep two things in mind:

  • always create the dependent feature branch with jiri cl new from the parent feature branch, and
  • after a parent feature has been submitted, cleanup the parent feature branch with jiri cl cleanup, and merge master into all dependent CLs and upload new patch sets.

FAQ

Why the name "jiri"?

Jiří is a very popular boys name in the Czech Republic.

How do you pronounce "jiri"?

We pronounce "jiri" like "yiree".

The actual Czech name Jiří is pronounced something like "yirzhee".

Why can't I commit to my master branch?

Jiri keeps the master branch of each project in the state described in the manifest. Any changes that are made to the master branch would be lost during the next jiri update.

Documentation

Overview

Package jiri provides utilities used by the jiri tool and related tools.

Index

Constants

View Source
const (
	RootEnv          = "JIRI_ROOT"
	RootMetaDir      = ".jiri_root"
	ProjectMetaDir   = ".jiri"
	ProjectMetaFile  = "metadata.v2"
	ProfilesDBDir    = RootMetaDir + string(filepath.Separator) + "profile_db"
	ProfilesRootDir  = RootMetaDir + string(filepath.Separator) + "profiles"
	JiriManifestFile = ".jiri_manifest"

	// PreservePathEnv is the name of the environment variable that, when set to a
	// non-empty value, causes jiri tools to use the existing PATH variable,
	// rather than mutating it.
	PreservePathEnv = "JIRI_PRESERVE_PATH"
)

Variables

This section is empty.

Functions

func ExpandEnv

func ExpandEnv(x *X, env *envvar.Vars)

ExpandEnv expands all instances of the JIRI_ROOT variable in the supplied environment with the root from jirix.

func FindRoot

func FindRoot() string

FindRoot returns the root directory of the jiri environment. All state managed by jiri resides under this root.

If the RootEnv environment variable is non-empty, we always attempt to use it. It must point to an absolute path, after symlinks are evaluated. TODO(toddw): Walk up the filesystem too.

Returns an empty string if the root directory cannot be determined, or if any errors are encountered.

FindRoot should be rarely used; typically you should use NewX to create a new execution environment, and handle errors. An example of a valid usage is to initialize default flag values in an init func before main.

func RunnerFunc

func RunnerFunc(run func(*X, []string) error) cmdline.Runner

RunnerFunc is an adapter that turns regular functions into cmdline.Runner. This is similar to cmdline.RunnerFunc, but the first function argument is jiri.X, rather than cmdline.Env.

Types

type RelPath

type RelPath string

RelPath represents a relative path whose root is JIRI_ROOT.

func NewRelPath

func NewRelPath(components ...string) RelPath

NewRelPath returns a RelPath with path consisting of the specified components.

func (RelPath) Abs

func (rp RelPath) Abs(x *X) string

Abs returns an absolute path corresponding to the RelPath rooted at the JIRI_ROOT in X.

func (RelPath) Join

func (rp RelPath) Join(components ...string) RelPath

Join returns a copy of RelPath with the specified components appended to the path using filepath.Join.

func (RelPath) Symbolic

func (rp RelPath) Symbolic() string

Symbolic returns an absolute path corresponding to the RelPath, but with the JIRI_ROOT environment varible at the root instead of the actual value of JIRI_ROOT.

type X

type X struct {
	*tool.Context
	Root  string
	Usage func(format string, args ...interface{}) error
}

X holds the execution environment for the jiri tool and related tools. This includes the jiri filesystem root directory.

TODO(toddw): Other jiri state should be transitioned to this struct, including the manifest and related operations.

func NewX

func NewX(env *cmdline.Env) (*X, error)

NewX returns a new execution environment, given a cmdline env. It also prepends $JIRI_ROOT/.jiri_root/bin to the PATH.

func (*X) BinDir

func (x *X) BinDir() string

BinDir returns the path to the bin directory.

func (*X) Clone

func (x *X) Clone(opts tool.ContextOpts) *X

Clone returns a clone of the environment.

func (*X) JiriManifestFile

func (x *X) JiriManifestFile() string

JiriManifestFile returns the path to the .jiri_manifest file.

func (*X) ProfilesDBDir

func (x *X) ProfilesDBDir() string

ProfilesDBDir returns the path to the profiles data base directory.

func (*X) ProfilesRootDir

func (x *X) ProfilesRootDir() string

ProfilesRootDir returns the path to the root of the profiles installation.

func (*X) RootMetaDir

func (x *X) RootMetaDir() string

RootMetaDir returns the path to the root metadata directory.

func (*X) ScriptsDir

func (x *X) ScriptsDir() string

ScriptsDir returns the path to the scripts directory.

func (*X) UpdateHistoryDir

func (x *X) UpdateHistoryDir() string

UpdateHistoryDir returns the path to the update history directory.

func (x *X) UpdateHistoryLatestLink() string

UpdateHistoryLatestLink returns the path to a symlink that points to the latest update in the update history directory.

func (x *X) UpdateHistorySecondLatestLink() string

UpdateHistorySecondLatestLink returns the path to a symlink that points to the second latest update in the update history directory.

func (*X) UsageErrorf

func (x *X) UsageErrorf(format string, args ...interface{}) error

UsageErrorf prints the error message represented by the printf-style format and args, followed by the usage output. The implementation typically calls cmdline.Env.UsageErrorf.

Directories

Path Synopsis
cmd
jiri
Command jiri is a multi-purpose tool for multi-repo development.
Command jiri is a multi-purpose tool for multi-repo development.
Package gerrit provides library functions for interacting with the gerrit code review system.
Package gerrit provides library functions for interacting with the gerrit code review system.
Package gitutil provides Go wrappers for various Git commands.
Package gitutil provides Go wrappers for various Git commands.
Package jiritest provides utilities for testing jiri functionality.
Package jiritest provides utilities for testing jiri functionality.
Package profiles and its subdirectoris implement support for managing external sofware dependencies.
Package profiles and its subdirectoris implement support for managing external sofware dependencies.
profilescmdline
Package profilescmdline provides a command line driver (for v.io/x/lib/cmdline) for implementing jiri 'profile' subcommands.
Package profilescmdline provides a command line driver (for v.io/x/lib/cmdline) for implementing jiri 'profile' subcommands.
profilescmdline/internal/i1
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
profilescmdline/internal/i2
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
Profiles are used to manage external sofware dependencies and offer a balance between providing no support at all and a full blown package manager.
profilesmanager
Package profilesmanager provides support for managing jiri profiles.
Package profilesmanager provides support for managing jiri profiles.
profilesreader
Package profilesreader provides support for reading and processing jiri profiles.
Package profilesreader provides support for reading and processing jiri profiles.
profilesutil
package profilesutil provides utility routines for implementing profiles.
package profilesutil provides utility routines for implementing profiles.
Package project contains library functions for working with jiri projects.
Package project contains library functions for working with jiri projects.
Package retry provides a facility for retrying function invocations.
Package retry provides a facility for retrying function invocations.
Package tool contains abstractions for working with developer tools.
Package tool contains abstractions for working with developer tools.

Jump to

Keyboard shortcuts

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