Skip to content
Merged
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
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,18 +431,3 @@ Options:
--verbose Show verbose output.
-?, -h, --help Show help and usage information
```

#### `stack config migrate` <!-- omit from toc -->

Migrate the configuration file from v1 to v2 format.

```shell
Usage:
stack config migrate [options]

Options:
--working-dir The path to the directory containing the git repository. Defaults to the current directory.
--verbose Show verbose output.
-y, --yes Confirm the command without prompting.
-?, -h, --help Show help and usage information
```
107 changes: 0 additions & 107 deletions src/Stack.Tests/Commands/Config/MigrateConfigCommandTests.cs

This file was deleted.

38 changes: 36 additions & 2 deletions src/Stack.Tests/Config/FileStackConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Load_WhenConfigFileDoesNotExist_ReturnsEmptyList()
}

[Fact]
public void Load_WhenConfigFileIsInV1Format_LoadsCorrectly()
public void Load_WhenConfigFileIsInV1Format_LoadsCorrectly_MigratesAndSavesFileInV2Format()
{
// Arrange
using var tempDirectory = TemporaryDirectory.Create();
Expand Down Expand Up @@ -67,7 +67,41 @@ public void Load_WhenConfigFileIsInV1Format_LoadsCorrectly()
var stackData = fileStackConfig.Load();

// Assert
stackData.Should().BeEquivalentTo(new StackData(SchemaVersion.V1, [expectedStack]));
stackData.Should().BeEquivalentTo(new StackData(SchemaVersion.V2, [expectedStack]));
var savedJson = File.ReadAllText(configPath);
var expectedJson = $@"{{
""SchemaVersion"": 2,
""Stacks"": [
{{
""Name"": ""{stackName}"",
""RemoteUri"": ""{remoteUri}"",
""SourceBranch"": ""{sourceBranch}"",
""Branches"": [
{{
""Name"": ""{branch1}"",
""Children"": [
{{
""Name"": ""{branch2}"",
""Children"": []
}}
]
}}
]
}}
]
}}";

// Normalize both JSON strings to remove whitespace differences
var normalizedSavedJson = NormalizeJsonString(savedJson);
var normalizedExpectedJson = NormalizeJsonString(expectedJson);

normalizedSavedJson.Should().Be(normalizedExpectedJson);

// Original backup should be in V1 format
var backupPath = fileStackConfig.GetV1ConfigBackupFilePath();
File.Exists(backupPath).Should().BeTrue();
var backupJson = File.ReadAllText(backupPath);
backupJson.Should().Be(v1Json);
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion src/Stack/Commands/Config/ConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class ConfigCommand : GroupCommand
{
public ConfigCommand() : base("config", "Manage stack configuration.")
{
Add(new MigrateConfigCommand());
Add(new OpenConfigCommand());
}
}
47 changes: 0 additions & 47 deletions src/Stack/Commands/Config/MigrateConfigCommand.cs

This file was deleted.

7 changes: 5 additions & 2 deletions src/Stack/Config/StackConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public StackData Load()
return new StackData(SchemaVersion.V2, LoadStacksFromV2Format(jsonString));
}

// If no schema version, this means v1 format, which we need to convert to v2.
return new StackData(SchemaVersion.V1, LoadStacksFromV1Format(jsonString));
// If no schema version, this means v1 format - migrate to v2 format and re-save before returning
var stacksV1 = LoadStacksFromV1Format(jsonString);
var stacks = new StackData(SchemaVersion.V2, stacksV1);
Save(stacks);
return stacks;
}

public void Save(StackData stackData)
Expand Down
Loading