aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
Diffstat (limited to 'options.go')
-rw-r--r--options.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/options.go b/options.go
index 5367031..d222267 100644
--- a/options.go
+++ b/options.go
@@ -373,6 +373,12 @@ var (
ErrMissingAuthor = errors.New("author field is required")
)
+// AddOptions describes how a add operation should be performed
+type AddOptions struct {
+ All bool
+ Path string
+}
+
// CommitOptions describes how a commit operation should be performed.
type CommitOptions struct {
// All automatically stage files that have been modified and deleted, but
@@ -464,7 +470,8 @@ var (
// CreateTagOptions describes how a tag object should be created.
type CreateTagOptions struct {
- // Tagger defines the signature of the tag creator.
+ // Tagger defines the signature of the tag creator. If Tagger is empty the
+ // Name and Email is read from the config, and time.Now it's used as When.
Tagger *object.Signature
// Message defines the annotation of the tag. It is canonicalized during
// validation into the format expected by git - no leading whitespace and
@@ -478,7 +485,9 @@ type CreateTagOptions struct {
// Validate validates the fields and sets the default values.
func (o *CreateTagOptions) Validate(r *Repository, hash plumbing.Hash) error {
if o.Tagger == nil {
- return ErrMissingTagger
+ if err := o.loadConfigTagger(r); err != nil {
+ return err
+ }
}
if o.Message == "" {
@@ -491,6 +500,35 @@ func (o *CreateTagOptions) Validate(r *Repository, hash plumbing.Hash) error {
return nil
}
+func (o *CreateTagOptions) loadConfigTagger(r *Repository) error {
+ cfg, err := r.ConfigScoped(config.SystemScope)
+ if err != nil {
+ return err
+ }
+
+ if o.Tagger == nil && cfg.Author.Email != "" && cfg.Author.Name != "" {
+ o.Tagger = &object.Signature{
+ Name: cfg.Author.Name,
+ Email: cfg.Author.Email,
+ When: time.Now(),
+ }
+ }
+
+ if o.Tagger == nil && cfg.User.Email != "" && cfg.User.Name != "" {
+ o.Tagger = &object.Signature{
+ Name: cfg.User.Name,
+ Email: cfg.User.Email,
+ When: time.Now(),
+ }
+ }
+
+ if o.Tagger == nil {
+ return ErrMissingTagger
+ }
+
+ return nil
+}
+
// ListOptions describes how a remote list should be performed.
type ListOptions struct {
// Auth credentials, if required, to use with the remote repository.