mirror of
https://github.com/abhinav/git-spice.git
synced 2026-08-31 07:47:47 +02:00
8456ed907f
Summary `gs branch merge`, `gs downstack merge`, and `gs stack merge` now accept repeated `--branch` flags. This lets one merge command combine multiple requested branch scopes and normalize overlapping branches before scheduling the merge. Details `gs branch merge` treats repeated `--branch` values as an exact selected set. The selected set must include every non-trunk branch needed to form a path to trunk. `gs downstack merge` and `gs stack merge` expand each requested branch through their normal scope rules. The merge handler then deduplicates overlapping scopes before building the merge queue. `gs stack merge` preserves the existing local-only branch behavior: branches without submitted change requests are skipped instead of blocking submitted changes from merging. The command help describes repeated `--branch` usage. Script coverage verifies branch merge, downstack merge, and stack merge scope normalization with full ShamHub JSON comparisons. [skip changelog]: unreleased merge feature
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/alecthomas/kong"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.abhg.dev/gs/internal/git"
|
|
)
|
|
|
|
func TestMergeCommandBranchFlag_acceptsRepeatedValues(t *testing.T) {
|
|
t.Run("BranchMerge", func(t *testing.T) {
|
|
var cmd branchMergeCmd
|
|
parser, err := newMergeCommandParser(t, &cmd)
|
|
require.NoError(t, err)
|
|
|
|
_, err = parser.Parse([]string{
|
|
"--branch", "feat1",
|
|
"--branch", "feat2",
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"feat1", "feat2"}, cmd.Branches)
|
|
})
|
|
|
|
t.Run("DownstackMerge", func(t *testing.T) {
|
|
var cmd downstackMergeCmd
|
|
parser, err := newMergeCommandParser(t, &cmd)
|
|
require.NoError(t, err)
|
|
|
|
_, err = parser.Parse([]string{
|
|
"--branch", "feat1",
|
|
"--branch", "feat2",
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"feat1", "feat2"}, cmd.Branches)
|
|
})
|
|
|
|
t.Run("StackMerge", func(t *testing.T) {
|
|
var cmd stackMergeCmd
|
|
parser, err := newMergeCommandParser(t, &cmd)
|
|
require.NoError(t, err)
|
|
|
|
_, err = parser.Parse([]string{
|
|
"--branch", "feat1",
|
|
"--branch", "feat2",
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"feat1", "feat2"}, cmd.Branches)
|
|
})
|
|
}
|
|
|
|
func TestMergeCommandBranchFlag_acceptsCommaSeparatedValues(t *testing.T) {
|
|
var cmd branchMergeCmd
|
|
parser, err := newMergeCommandParser(t, &cmd)
|
|
require.NoError(t, err)
|
|
|
|
_, err = parser.Parse([]string{
|
|
"--branch", "feat1,feat2",
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"feat1", "feat2"}, cmd.Branches)
|
|
}
|
|
|
|
func newMergeCommandParser(t *testing.T, cmd any) (*kong.Kong, error) {
|
|
t.Helper()
|
|
|
|
return kong.New(cmd,
|
|
kong.BindTo(t.Context(), (*context.Context)(nil)),
|
|
kong.Bind((*git.Worktree)(nil)),
|
|
)
|
|
}
|