@@ -802,6 +802,80 @@ func TestIntegration_SendNoStack(t *testing.T) {
802802 }
803803}
804804
805+ func TestIntegration_SendRebase (t * testing.T ) {
806+ checkJJ (t )
807+
808+ mock := newMockService ()
809+ repoDir , _ := initTestRepoWithRemote (t )
810+ spy := & spyRunner {Runner : jj .NewRunner (repoDir )}
811+
812+ // Create a change on top of main.
813+ writeAndCommit (t , repoDir , "a.go" , "package a" , "feat: rebase test" )
814+
815+ var buf bytes.Buffer
816+ err := executeSend (spy , mock , sendOpts {
817+ base : "main" ,
818+ remote : "origin" ,
819+ revsets : []string {"@-" },
820+ rebase : true ,
821+ }, & buf )
822+ if err != nil {
823+ t .Fatalf ("send --rebase failed: %v\n Output:\n %s" , err , buf .String ())
824+ }
825+
826+ output := buf .String ()
827+ t .Logf ("Output:\n %s" , output )
828+
829+ // Verify rebase was called with the correct arguments.
830+ if len (spy .rebaseCalls ) != 1 {
831+ t .Fatalf ("expected 1 rebase call, got %d" , len (spy .rebaseCalls ))
832+ }
833+ rc := spy .rebaseCalls [0 ]
834+ if len (rc .revsets ) != 1 || rc .revsets [0 ] != "@-" {
835+ t .Errorf ("expected rebase revsets [@-], got %v" , rc .revsets )
836+ }
837+ if rc .destination != "main" {
838+ t .Errorf ("expected rebase destination 'main', got %q" , rc .destination )
839+ }
840+
841+ // Output should mention rebasing.
842+ if ! strings .Contains (output , "Rebasing onto main" ) {
843+ t .Errorf ("expected 'Rebasing onto main' in output, got:\n %s" , output )
844+ }
845+
846+ // PR should still be created successfully.
847+ mock .mu .Lock ()
848+ defer mock .mu .Unlock ()
849+ if len (mock .prs ) != 1 {
850+ t .Errorf ("expected 1 PR, got %d" , len (mock .prs ))
851+ }
852+ }
853+
854+ func TestIntegration_SendNoRebaseByDefault (t * testing.T ) {
855+ checkJJ (t )
856+
857+ mock := newMockService ()
858+ repoDir , _ := initTestRepoWithRemote (t )
859+ spy := & spyRunner {Runner : jj .NewRunner (repoDir )}
860+
861+ writeAndCommit (t , repoDir , "a.go" , "package a" , "feat: no rebase test" )
862+
863+ var buf bytes.Buffer
864+ err := executeSend (spy , mock , sendOpts {
865+ base : "main" ,
866+ remote : "origin" ,
867+ revsets : []string {"@-" },
868+ }, & buf )
869+ if err != nil {
870+ t .Fatalf ("send failed: %v\n Output:\n %s" , err , buf .String ())
871+ }
872+
873+ // Rebase should NOT have been called.
874+ if len (spy .rebaseCalls ) != 0 {
875+ t .Errorf ("expected 0 rebase calls without --rebase, got %d" , len (spy .rebaseCalls ))
876+ }
877+ }
878+
805879func TestIntegration_SendSkipsBehindBookmark (t * testing.T ) {
806880 checkJJ (t )
807881
@@ -985,11 +1059,17 @@ func writeFile(t *testing.T, dir, filename, content string) {
9851059 }
9861060}
9871061
988- // spyRunner wraps a real Runner and records remotes passed to GitFetch/GitPush.
1062+ // spyRunner wraps a real Runner and records remotes passed to GitFetch/GitPush/Rebase .
9891063type spyRunner struct {
9901064 jj.Runner
9911065 fetchRemotes []string
9921066 pushRemote string
1067+ rebaseCalls []rebaseCall
1068+ }
1069+
1070+ type rebaseCall struct {
1071+ revsets []string
1072+ destination string
9931073}
9941074
9951075func (s * spyRunner ) GitFetch (remote string ) error {
@@ -1002,6 +1082,11 @@ func (s *spyRunner) GitPush(bookmarks []string, allowNew bool, remote string) er
10021082 return s .Runner .GitPush (bookmarks , allowNew , remote )
10031083}
10041084
1085+ func (s * spyRunner ) Rebase (revsets []string , destination string ) error {
1086+ s .rebaseCalls = append (s .rebaseCalls , rebaseCall {revsets : revsets , destination : destination })
1087+ return s .Runner .Rebase (revsets , destination )
1088+ }
1089+
10051090// --- Test helpers ---
10061091
10071092func checkJJ (t * testing.T ) {
0 commit comments