Skip to content

Config option to always create annotated tags #4774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ git:
# The commit message to use for a squash merge commit. Can contain "{{selectedRef}}" and "{{currentBranch}}" placeholders.
squashMergeMessage: Squash merge {{selectedRef}} into {{currentBranch}}

# Config relating to tagging
tag:
# If true, always create annotated tags (even if the tag message is empty)
alwaysAnnotate: false

# list of branches that are considered 'main' branches, used when displaying commits
mainBranches:
- master
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ git:
# The commit message to use for a squash merge commit. Can contain "{{selectedRef}}" and "{{currentBranch}}" placeholders.
squashMergeMessage: Squash merge {{selectedRef}} into {{currentBranch}}

# Config relating to tagging
tag:
# If true, always create annotated tags (even if the tag message is empty)
alwaysAnnotate: false

# list of branches that are considered 'main' branches, used when displaying commits
mainBranches:
- master
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ type GitConfig struct {
Commit CommitConfig `yaml:"commit"`
// Config relating to merging
Merging MergingConfig `yaml:"merging"`
// Config relating to tagging
Tag TagConfig `yaml:"tag"`
// list of branches that are considered 'main' branches, used when displaying commits
MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true"`
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
Expand Down Expand Up @@ -341,6 +343,11 @@ type MergingConfig struct {
SquashMergeMessage string `yaml:"squashMergeMessage"`
}

type TagConfig struct {
// If true, always create annotated tags (even if the tag message is empty)
AlwaysAnnotate bool `yaml:"alwaysAnnotate"`
}

type LogConfig struct {
// One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'
// 'topo-order' makes it easier to read the git log graph, but commits may not
Expand Down Expand Up @@ -809,6 +816,9 @@ func GetDefaultConfig() *UserConfig {
Args: "",
SquashMergeMessage: "Squash merge {{selectedRef}} into {{currentBranch}}",
},
Tag: TagConfig{
AlwaysAnnotate: false,
},
Log: LogConfig{
Order: "topo-order",
ShowGraph: "always",
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/helpers/tags_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error {
Prompt: prompt,
HandleConfirm: func() error {
var command *oscommands.CmdObj
if description != "" || self.c.Git().Config.GetGpgTagSign() {
if description != "" || self.c.Git().Config.GetGpgTagSign() || self.c.UserConfig().Git.Tag.AlwaysAnnotate {
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
command = self.c.Git().Tag.CreateAnnotatedObj(tagName, ref, description, force)
} else {
Expand Down
11 changes: 11 additions & 0 deletions pkg/integration/components/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ func (self *Git) TagNamesAt(ref string, expectedNames []string) *Git {
return self.assert([]string{"git", "tag", "--sort=v:refname", "--points-at", ref}, strings.Join(expectedNames, "\n"))
}

func (self *Git) TagIsAnnotated(tagName string) *Git {
cmdArgs := []string{"git", "cat-file", "-t", tagName}
expectedOutput := "tag"

return self.expect(cmdArgs, func(output string) (bool, string) {
isAnnotated := output == expectedOutput
failureMessage := fmt.Sprintf("Expected tag '%s' to be an annotated tag (output 'tag'), but got '%s'", tagName, output)
return isAnnotated, failureMessage
})
}

func (self *Git) RemoteTagDeleted(ref string, tagName string) *Git {
return self.expect([]string{"git", "ls-remote", ref, fmt.Sprintf("refs/tags/%s", tagName)}, func(s string) (bool, string) {
return len(s) == 0, fmt.Sprintf("Expected tag %s to have been removed from %s", tagName, ref)
Expand Down
37 changes: 37 additions & 0 deletions pkg/integration/tests/tag/create_annotated_with_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tag

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var CreateAnnotatedWithConfig = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Create an annotated tag when the alwaysAnnotate config option is enabled",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.Tag.AlwaysAnnotate = true
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Tags().
Focus().
IsEmpty().
Press(keys.Universal.New).
Tap(func() {
t.ExpectPopup().CommitMessagePanel().
Title(Equals("Tag name")).
Type("new-tag").
Confirm()
}).
Lines(
MatchesRegexp(`new-tag.*`).IsSelected(),
).
PressEnter().
Tap(func() {
t.Git().TagIsAnnotated("new-tag")
})
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ var tests = []*components.IntegrationTest{
tag.Checkout,
tag.CheckoutWhenBranchWithSameNameExists,
tag.CopyToClipboard,
tag.CreateAnnotatedWithConfig,
tag.CreateWhileCommitting,
tag.CrudAnnotated,
tag.CrudLightweight,
Expand Down
16 changes: 16 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@
"$ref": "#/$defs/MergingConfig",
"description": "Config relating to merging"
},
"tag": {
"$ref": "#/$defs/TagConfig",
"description": "Config relating to tagging"
},
"mainBranches": {
"items": {
"type": "string"
Expand Down Expand Up @@ -1727,6 +1731,18 @@
"type": "object",
"description": "Config relating to the spinner."
},
"TagConfig": {
"properties": {
"alwaysAnnotate": {
"type": "boolean",
"description": "If true, always create annotated tags (even if the tag message is empty)",
"default": false
}
},
"additionalProperties": false,
"type": "object",
"description": "Config relating to tagging"
},
"ThemeConfig": {
"properties": {
"activeBorderColor": {
Expand Down