Skip to content
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

Auto-upgrade outdated push-verify config option #2209

Merged
merged 51 commits into from Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c1ec978
upgrade.feature auto_upgrade_outdated_configuration.feature git_town.…
kevgo Apr 6, 2023
639f0ab
Unify BackendRunner and BackendLoggingRunner
kevgo Apr 6, 2023
7dd1c2b
backend_runner.go
kevgo Apr 6, 2023
aa7eea2
backend_runner.go
kevgo Apr 6, 2023
e125140
Merge branch 'kg-single-backend-runner' into kg-consistent-setting-steps
kevgo Apr 6, 2023
aa80ca8
backend_runner.go
kevgo Apr 6, 2023
94ee623
Merge branch 'kg-single-backend-runner' into kg-consistent-setting-steps
kevgo Apr 6, 2023
72e2268
backend_runner.go
kevgo Apr 6, 2023
bf40fc6
Merge branch 'kg-single-backend-runner' into kg-consistent-setting-steps
kevgo Apr 6, 2023
340e289
Preserve value while upgrading outdated configuration
kevgo Apr 6, 2023
40c6fa3
Use constants for configuration keys
kevgo Apr 6, 2023
9906779
Merge branch 'kg-use-const-keys' into kg-preserve-value-while-upgradi…
kevgo Apr 6, 2023
b82574d
Merge branch 'kg-preserve-value-while-upgrading-outdated-config-setti…
kevgo Apr 6, 2023
ff460c4
auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
69c27b9
Merge branch 'main' into kg-use-const-keys
kevgo Apr 6, 2023
17a5c9f
Merge branch 'kg-use-const-keys' into kg-preserve-value-while-upgradi…
kevgo Apr 6, 2023
9b233b6
Merge branch 'kg-preserve-value-while-upgrading-outdated-config-setti…
kevgo Apr 6, 2023
0c7afa5
Merge branch 'main' into kg-use-const-keys
kevgo Apr 6, 2023
deacf04
Merge branch 'kg-use-const-keys' into kg-preserve-value-while-upgradi…
kevgo Apr 6, 2023
5664d57
Merge branch 'kg-preserve-value-while-upgrading-outdated-config-setti…
kevgo Apr 6, 2023
853350c
Merge branch 'main' into kg-use-const-keys
kevgo Apr 6, 2023
dfff3b1
Merge branch 'kg-use-const-keys' into kg-consistent-setting-steps
kevgo Apr 6, 2023
b09d784
auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
efe57ac
auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
071c681
auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
64a185a
auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
166211b
auto_upgrade_outdated_configuration.feature core.go git_town.go
kevgo Apr 6, 2023
87bb5b3
Mark keys for deprecated config settings
kevgo Apr 6, 2023
8bc05ee
Merge branch 'kg-mark-deprecated-config-keys' into kg-update-push-ver…
kevgo Apr 6, 2023
7d65a60
auto_upgrade_outdated_configuration.feature git_town.go
kevgo Apr 6, 2023
8e09c78
Merge branch 'main' into kg-upgrade-config-all-commands
kevgo Apr 6, 2023
6e3da7c
Merge branch 'kg-upgrade-config-all-commands' into kg-mark-deprecated…
kevgo Apr 6, 2023
4c34a81
Merge branch 'kg-mark-deprecated-config-keys' into kg-update-push-ver…
kevgo Apr 6, 2023
a6e474f
auto_upgrade.feature auto_upgrade_outdated_configuration.feature
kevgo Apr 6, 2023
e7edb35
auto_upgrade.feature auto_upgrade.feature auto_upgrade_outdated_confi…
kevgo Apr 6, 2023
aca265c
Merge branch 'main' into kg-mark-deprecated-config-keys
kevgo Apr 6, 2023
0f26ec7
Merge branch 'kg-mark-deprecated-config-keys' into kg-update-push-ver…
kevgo Apr 6, 2023
4d5bbcc
Merge branch 'main' into kg-update-push-verify-to-push-hook
kevgo Apr 6, 2023
ac6ce62
auto_upgrade.feature
kevgo Apr 6, 2023
e4b37f2
upgrade.feature
kevgo Apr 6, 2023
6e6660f
git_town.go
kevgo Apr 6, 2023
59ed1ce
git_town.go
kevgo Apr 6, 2023
c51ccca
upgrade.feature
kevgo Apr 6, 2023
6edf305
git_town.go
kevgo Apr 6, 2023
4954c3c
git_town.go
kevgo Apr 6, 2023
0d40a54
upgrade.feature upgrade.feature
kevgo Apr 6, 2023
21a108c
upgrade.feature
kevgo Apr 6, 2023
4e9fba0
upgrade.feature
kevgo Apr 6, 2023
e89be93
upgrade.feature
kevgo Apr 6, 2023
041c7b3
upgrade.feature
kevgo Apr 6, 2023
5009df7
git_town.go
kevgo Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions features/config/push_hook/upgrade.feature
@@ -0,0 +1,36 @@
Feature: automatically upgrade outdated configuration

Scenario Outline:
Given <LOCATION> setting "push-verify" is "true"
And the current branch is a feature branch "feature"
And tool "open" is installed
And the origin is "git@github.com:git-town/git-town.git"
When I run "git-town <COMMAND>"
Then it prints:
"""
I found the deprecated <LOCATION> setting "git-town.push-verify".
I am upgrading this setting to the new format "git-town.push-hook".
"""
And <LOCATION> setting "push-hook" is now "true"
And <LOCATION> setting "push-verify" no longer exists

Examples:
| COMMAND | LOCATION |
| config | local |
| config | global |
| config push-hook | local |
| config push-hook | global |
| append foo | local |
| append foo | global |
| hack foo | local |
| hack foo | global |
| prepend foo | local |
| prepend foo | global |
| sync | local |
| sync | global |
| kill | local |
| kill | global |
| new-pull-request | local |
| new-pull-request | global |
| rename-branch bar | local |
| rename-branch bar | global |
4 changes: 2 additions & 2 deletions features/config/push_new_branches/upgrade.feature
Expand Up @@ -14,12 +14,12 @@ Feature: automatically upgrade outdated configuration

Examples:
| COMMAND | LOCATION |
| append foo | local |
| append foo | global |
| config | local |
| config | global |
| config push-new-branches | local |
| config push-new-branches | global |
| append foo | local |
| append foo | global |
| hack foo | local |
| hack foo | global |
| prepend foo | local |
Expand Down
1 change: 1 addition & 0 deletions src/config/core.go
Expand Up @@ -8,6 +8,7 @@ const (
CodeHostingDriverKey = "git-town.code-hosting-driver"
CodeHostingOriginHostnameKey = "git-town.code-hosting-origin-hostname"
DeprecatedNewBranchPushFlagKey = "git-town.new-branch-push-flag"
DeprecatedPushVerifyKey = "git-town.push-verify"
GiteaTokenKey = "git-town.gitea-token" //nolint:gosec
GithubTokenKey = "git-town.github-token" //nolint:gosec
GitlabTokenKey = "git-town.gitlab-token" //nolint:gosec
Expand Down
86 changes: 61 additions & 25 deletions src/config/git_town.go
Expand Up @@ -89,6 +89,14 @@ func (gt *GitTown) DeprecatedNewBranchPushFlagLocal() string {
return gt.localConfigCache[DeprecatedNewBranchPushFlagKey]
}

func (gt *GitTown) DeprecatedPushVerifyFlagGlobal() string {
return gt.globalConfigCache[DeprecatedPushVerifyKey]
}

func (gt *GitTown) DeprecatedPushVerifyFlagLocal() string {
return gt.localConfigCache[DeprecatedPushVerifyKey]
}

// GitAlias provides the currently set alias for the given Git Town command.
func (gt *GitTown) GitAlias(aliasType AliasType) string {
return gt.GlobalConfigValue("alias." + string(aliasType))
Expand Down Expand Up @@ -257,6 +265,10 @@ func (gt *GitTown) PullBranchStrategy() (PullBranchStrategy, error) {

// PushHook provides the currently configured push-hook setting.
func (gt *GitTown) PushHook() (bool, error) {
err := gt.updateDeprecatedSetting(DeprecatedPushVerifyKey, PushHookKey)
if err != nil {
return false, err
}
setting := gt.LocalOrGlobalConfigValue(PushHookKey)
if setting == "" {
return true, nil
Expand All @@ -270,6 +282,10 @@ func (gt *GitTown) PushHook() (bool, error) {

// PushHook provides the currently configured push-hook setting.
func (gt *GitTown) PushHookGlobal() (bool, error) {
err := gt.updateDeprecatedGlobalSetting(DeprecatedPushVerifyKey, PushHookKey)
if err != nil {
return false, err
}
setting := gt.GlobalConfigValue(PushHookKey)
if setting == "" {
return true, nil
Expand Down Expand Up @@ -426,31 +442,9 @@ func (gt *GitTown) SetTestOrigin(value string) error {
// ShouldNewBranchPush indicates whether the current repository is configured to push
// freshly created branches up to origin.
func (gt *GitTown) ShouldNewBranchPush() (bool, error) {
oldLocalConfig := gt.DeprecatedNewBranchPushFlagLocal()
if oldLocalConfig != "" {
fmt.Printf("I found the deprecated local setting %q.\n", DeprecatedNewBranchPushFlagKey)
fmt.Printf("I am upgrading this setting to the new format %q.\n", PushNewBranchesKey)
err := gt.RemoveLocalConfigValue(DeprecatedNewBranchPushFlagKey)
if err != nil {
return false, err
}
_, err = gt.SetLocalConfigValue(PushNewBranchesKey, oldLocalConfig)
if err != nil {
return false, err
}
}
oldGlobalConfig := gt.DeprecatedNewBranchPushFlagGlobal()
if oldGlobalConfig != "" {
fmt.Printf("I found the deprecated global setting %q.\n", DeprecatedNewBranchPushFlagKey)
fmt.Printf("I am upgrading this setting to the new format %q.\n", PushNewBranchesKey)
_, err := gt.RemoveGlobalConfigValue(DeprecatedNewBranchPushFlagKey)
if err != nil {
return false, err
}
_, err = gt.SetGlobalConfigValue(PushNewBranchesKey, oldGlobalConfig)
if err != nil {
return false, err
}
err := gt.updateDeprecatedSetting(DeprecatedNewBranchPushFlagKey, PushNewBranchesKey)
if err != nil {
return false, err
}
config := gt.LocalOrGlobalConfigValue(PushNewBranchesKey)
if config == "" {
Expand All @@ -466,6 +460,10 @@ func (gt *GitTown) ShouldNewBranchPush() (bool, error) {
// ShouldNewBranchPushGlobal indictes whether the global configuration requires to push
// freshly created branches to origin.
func (gt *GitTown) ShouldNewBranchPushGlobal() (bool, error) {
err := gt.updateDeprecatedGlobalSetting(DeprecatedNewBranchPushFlagKey, PushNewBranchesKey)
if err != nil {
return false, err
}
config := gt.GlobalConfigValue(PushNewBranchesKey)
if config == "" {
return false, nil
Expand Down Expand Up @@ -504,3 +502,41 @@ func (gt *GitTown) SyncStrategyGlobal() (SyncStrategy, error) {
setting := gt.GlobalConfigValue(SyncStrategyKey)
return ToSyncStrategy(setting)
}

func (gt *GitTown) updateDeprecatedSetting(deprecatedKey, newKey string) error {
err := gt.updateDeprecatedLocalSetting(deprecatedKey, newKey)
if err != nil {
return err
}
return gt.updateDeprecatedGlobalSetting(deprecatedKey, newKey)
}

func (gt *GitTown) updateDeprecatedGlobalSetting(deprecatedKey, newKey string) error {
deprecatedSetting := gt.GlobalConfigValue(deprecatedKey)
if deprecatedSetting != "" {
fmt.Printf("I found the deprecated global setting %q.\n", deprecatedKey)
fmt.Printf("I am upgrading this setting to the new format %q.\n", newKey)
_, err := gt.RemoveGlobalConfigValue(deprecatedKey)
if err != nil {
return err
}
_, err = gt.SetGlobalConfigValue(newKey, deprecatedSetting)
return err
}
return nil
}

func (gt *GitTown) updateDeprecatedLocalSetting(deprecatedKey, newKey string) error {
deprecatedSetting := gt.LocalConfigValue(deprecatedKey)
if deprecatedSetting != "" {
fmt.Printf("I found the deprecated local setting %q.\n", deprecatedKey)
fmt.Printf("I am upgrading this setting to the new format %q.\n", newKey)
err := gt.RemoveLocalConfigValue(deprecatedKey)
if err != nil {
return err
}
_, err = gt.SetLocalConfigValue(newKey, deprecatedSetting)
return err
}
return nil
}