Exemple #1
0
func diffRange(repo *git.Repository, commitRange *gg.CommitRange, contextLines uint32) result.Result {
	return result.Combine(func(values ...interface{}) result.Result {
		opts := values[2].(git.DiffOptions)
		opts.ContextLines = contextLines
		return result.NewResult(repo.DiffTreeToTree(
			values[0].(*git.Tree),
			values[1].(*git.Tree),
			&opts))
	}, commitTree(commitRange.Parent), commitTree(commitRange.Child), diffOptions())
}
Exemple #2
0
// @return result.Result<VersionStatus, error>
func writeVersion(repo *git.Repository, version string) result.Result {
	oid := result.NewResult(repo.CreateBlobFromBuffer([]byte(version)))
	return oid.FlatMap(func(oid interface{}) result.Result {
		path := filepath.Join(gg.CommentRefBase, versionRef)
		return result.NewResult(repo.References.Create(path,
			oid.(*git.Oid), false, upgradeMessage))
	}).FlatMap(func(ref interface{}) result.Result {
		return result.NewSuccess(VersionStatusEqual)
	})
}
Exemple #3
0
// @return result.Result<string, error>
func readVersion(repo *git.Repository) result.Result {
	path := filepath.Join(gg.CommentRefBase, versionRef)
	ref := result.NewResult(repo.References.Lookup(path))
	return ref.FlatMap(func(ref interface{}) result.Result {
		oid := ref.(*git.Reference).Target()
		return result.NewResult(repo.LookupBlob(oid))
	}).FlatMap(func(blob interface{}) result.Result {
		contents := blob.(*git.Blob).Contents()
		return result.NewSuccess(string(contents))
	})
}
Exemple #4
0
// Parse commits from commitish string, populating a CommitRange. If a
// single commit is matched, it is paired with its first parent commit
// or resolves to an error
//
// return result.Result<*git.Commit, error>
func ResolveCommits(repo *git.Repository, commitish string) result.Result {
	return result.NewResult(repo.Revparse(commitish)).FlatMap(func(value interface{}) result.Result {
		spec := value.(*git.Revspec)
		return resolveCommit(repo, spec.From()).FlatMap(func(f interface{}) result.Result {
			fromCommit := f.(*git.Commit)
			return resolveCommit(repo, spec.To()).Analysis(func(t interface{}) result.Result {
				toCommit := t.(*git.Commit)
				return result.NewSuccess(&CommitRange{fromCommit, toCommit})
			}, func(err error) result.Result {
				return resolveCommitParent(fromCommit).FlatMap(func(parent interface{}) result.Result {
					return result.NewSuccess(&CommitRange{parent.(*git.Commit), fromCommit})
				})
			})
		})
	})
}
Exemple #5
0
func resolveCommit(repo *git.Repository, object git.Object) result.Result {
	if object != nil && object.Type() == git.ObjectCommit {
		return result.NewResult(repo.LookupCommit(object.Id()))
	}
	return result.NewFailure(errors.New(noCommitError))
}
Exemple #6
0
// Parse the commit hash of a single commit from a reference, converting to HEAD
// where needed
//
// return result.Result<*string, error>
func ResolveSingleCommitHash(repo *git.Repository, commitish string) result.Result {
	return result.NewResult(repo.RevparseSingle(ExpandCommitish(commitish))).FlatMap(getObjectId)
}