@@ -1597,46 +1597,134 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
15971597 } ) ;
15981598
15991599 describe ( "commit context" , ( ) => {
1600- it . effect ( "stages selected files and commits only those files" , ( ) =>
1601- Effect . gen ( function * ( ) {
1602- const cwd = yield * makeTmpDir ( ) ;
1603- yield * initRepoWithCommit ( cwd ) ;
1604- const driver = yield * GitVcsDriver . GitVcsDriver ;
1600+ it . effect (
1601+ "prepares selected files without changing the index and commits only those files" ,
1602+ ( ) =>
1603+ Effect . gen ( function * ( ) {
1604+ const cwd = yield * makeTmpDir ( ) ;
1605+ yield * initRepoWithCommit ( cwd ) ;
1606+ const driver = yield * GitVcsDriver . GitVcsDriver ;
1607+
1608+ yield * writeTextFile ( cwd , "a.txt" , "a\n" ) ;
1609+ yield * writeTextFile ( cwd , "b.txt" , "b\n" ) ;
16051610
1606- yield * writeTextFile ( cwd , "a.txt" , "a\n" ) ;
1607- yield * writeTextFile ( cwd , "b.txt" , "b\n" ) ;
1611+ const context = yield * driver . prepareCommitContext ( cwd , [ "a.txt" ] ) ;
1612+ assert . include ( context ?. stagedSummary ?? "" , "a.txt" ) ;
1613+ assert . notInclude ( context ?. stagedSummary ?? "" , "b.txt" ) ;
1614+ assert . equal ( yield * git ( cwd , [ "diff" , "--cached" , "--name-only" ] ) , "" ) ;
16081615
1609- const context = yield * driver . prepareCommitContext ( cwd , [ "a.txt" ] ) ;
1610- assert . include ( context ?. stagedSummary ?? "" , "a.txt" ) ;
1611- assert . notInclude ( context ?. stagedSummary ?? "" , "b.txt" ) ;
1616+ const commit = yield * driver . commit ( cwd , "Add a" , "" , {
1617+ stage : { filePaths : [ "a.txt" ] } ,
1618+ } ) ;
1619+ assert . match ( commit . commitSha , / ^ [ a - f 0 - 9 ] { 40 } $ / ) ;
1620+ assert . equal ( yield * git ( cwd , [ "log" , "-1" , "--pretty=%s" ] ) , "Add a" ) ;
16121621
1613- const commit = yield * driver . commit ( cwd , "Add a" , "" ) ;
1614- assert . match ( commit . commitSha , / ^ [ a - f 0 - 9 ] { 40 } $ / ) ;
1615- assert . equal ( yield * git ( cwd , [ "log" , "-1" , "--pretty=%s" ] ) , "Add a" ) ;
1622+ const status = yield * git ( cwd , [ "status" , "--porcelain" ] ) ;
1623+ assert . include ( status , "?? b.txt" ) ;
1624+ assert . notInclude ( status , "a.txt" ) ;
1625+ } ) ,
1626+ ) ;
16161627
1617- const status = yield * git ( cwd , [ "status" , "--porcelain" ] ) ;
1618- assert . include ( status , "?? b.txt" ) ;
1619- assert . notInclude ( status , "a.txt" ) ;
1628+ it . effect ( "prepares selected files without clearing merge state" , ( ) =>
1629+ Effect . gen ( function * ( ) {
1630+ const cwd = yield * makeTmpDir ( ) ;
1631+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
1632+ const driver = yield * GitVcsDriver . GitVcsDriver ;
1633+ const fileSystem = yield * FileSystem . FileSystem ;
1634+ const pathService = yield * Path . Path ;
1635+
1636+ yield * git ( cwd , [ "checkout" , "-b" , "merge-source" ] ) ;
1637+ yield * writeTextFile ( cwd , "merge-source.txt" , "source\n" ) ;
1638+ yield * git ( cwd , [ "add" , "merge-source.txt" ] ) ;
1639+ yield * git ( cwd , [ "commit" , "-m" , "Add merge source" ] ) ;
1640+ yield * git ( cwd , [ "checkout" , initialBranch ] ) ;
1641+ yield * writeTextFile ( cwd , "main.txt" , "main\n" ) ;
1642+ yield * git ( cwd , [ "add" , "main.txt" ] ) ;
1643+ yield * git ( cwd , [ "commit" , "-m" , "Advance main" ] ) ;
1644+ yield * git ( cwd , [ "merge" , "--no-commit" , "--no-ff" , "merge-source" ] ) ;
1645+ yield * writeTextFile ( cwd , "selected.txt" , "selected\n" ) ;
1646+
1647+ const indexPath = pathService . join ( cwd , ".git" , "index" ) ;
1648+ const mergeHeadPath = pathService . join ( cwd , ".git" , "MERGE_HEAD" ) ;
1649+ const originalIndex = yield * fileSystem . readFile ( indexPath ) ;
1650+ const originalMergeHead = yield * fileSystem . readFile ( mergeHeadPath ) ;
1651+
1652+ const context = yield * driver . prepareCommitContext ( cwd , [ "selected.txt" ] ) ;
1653+
1654+ assert . include ( context ?. stagedSummary ?? "" , "selected.txt" ) ;
1655+ assert . deepEqual (
1656+ Array . from ( yield * fileSystem . readFile ( indexPath ) ) ,
1657+ Array . from ( originalIndex ) ,
1658+ ) ;
1659+ assert . deepEqual (
1660+ Array . from ( yield * fileSystem . readFile ( mergeHeadPath ) ) ,
1661+ Array . from ( originalMergeHead ) ,
1662+ ) ;
16201663 } ) ,
16211664 ) ;
16221665
16231666 it . effect ( "treats selected file paths literally" , ( ) =>
16241667 Effect . gen ( function * ( ) {
16251668 const cwd = yield * makeTmpDir ( ) ;
1626- yield * initRepoWithCommit ( cwd ) ;
1669+ yield * git ( cwd , [ "init" , "--initial-branch=main" ] ) ;
1670+ yield * git ( cwd , [ "config" , "user.email" , "[email protected] " ] ) ; 1671+ yield * git ( cwd , [ "config" , "user.name" , "Test" ] ) ;
16271672 const driver = yield * GitVcsDriver . GitVcsDriver ;
16281673
16291674 yield * writeTextFile ( cwd , "selected[1].txt" , "literal\n" ) ;
16301675 yield * writeTextFile ( cwd , "selected1.txt" , "pattern match\n" ) ;
1676+ yield * git ( cwd , [ "add" , "selected1.txt" ] ) ;
16311677
16321678 yield * driver . prepareCommitContext ( cwd , [ "selected[1].txt" ] ) ;
16331679
1634- assert . equal ( yield * git ( cwd , [ "diff" , "--cached" , "--name-only" ] ) , "selected[1].txt" ) ;
1680+ assert . equal ( yield * git ( cwd , [ "diff" , "--cached" , "--name-only" ] ) , "selected1.txt" ) ;
1681+ yield * driver . commit ( cwd , "Add literal path" , "" , {
1682+ stage : { filePaths : [ "selected[1].txt" ] } ,
1683+ } ) ;
1684+ assert . equal (
1685+ yield * git ( cwd , [ "diff-tree" , "--root" , "--no-commit-id" , "--name-only" , "-r" , "HEAD" ] ) ,
1686+ "selected[1].txt" ,
1687+ ) ;
16351688
16361689 const status = yield * git ( cwd , [ "status" , "--porcelain" ] ) ;
16371690 assert . include ( status , "?? selected1.txt" ) ;
16381691 } ) ,
16391692 ) ;
1693+
1694+ it . effect ( "includes force-added ignored files without changing the index" , ( ) =>
1695+ Effect . gen ( function * ( ) {
1696+ const cwd = yield * makeTmpDir ( ) ;
1697+ yield * initRepoWithCommit ( cwd ) ;
1698+ const driver = yield * GitVcsDriver . GitVcsDriver ;
1699+ const fileSystem = yield * FileSystem . FileSystem ;
1700+ const pathService = yield * Path . Path ;
1701+
1702+ yield * writeTextFile ( cwd , ".gitignore" , "*.generated\n" ) ;
1703+ yield * git ( cwd , [ "add" , ".gitignore" ] ) ;
1704+ yield * git ( cwd , [ "commit" , "-m" , "Ignore generated files" ] ) ;
1705+ yield * writeTextFile ( cwd , "included.generated" , "included\n" ) ;
1706+ yield * git ( cwd , [ "add" , "-f" , "included.generated" ] ) ;
1707+ const indexPath = pathService . join ( cwd , ".git" , "index" ) ;
1708+ const originalIndex = yield * fileSystem . readFile ( indexPath ) ;
1709+
1710+ const allFilesContext = yield * driver . prepareCommitContext ( cwd ) ;
1711+ const selectedFileContext = yield * driver . prepareCommitContext ( cwd , [ "included.generated" ] ) ;
1712+
1713+ assert . include ( allFilesContext ?. stagedSummary ?? "" , "included.generated" ) ;
1714+ assert . include ( selectedFileContext ?. stagedSummary ?? "" , "included.generated" ) ;
1715+ assert . deepEqual (
1716+ Array . from ( yield * fileSystem . readFile ( indexPath ) ) ,
1717+ Array . from ( originalIndex ) ,
1718+ ) ;
1719+ yield * driver . commit ( cwd , "Add generated file" , "" , {
1720+ stage : { filePaths : [ "included.generated" ] } ,
1721+ } ) ;
1722+ assert . equal (
1723+ yield * git ( cwd , [ "diff-tree" , "--no-commit-id" , "--name-only" , "-r" , "HEAD" ] ) ,
1724+ "included.generated" ,
1725+ ) ;
1726+ } ) ,
1727+ ) ;
16401728 } ) ;
16411729
16421730 describe ( "remote operations" , ( ) => {
@@ -1727,7 +1815,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
17271815 refName : "feature/push" ,
17281816 } ) ;
17291817 yield * writeTextFile ( cwd , "feature.txt" , "feature\n" ) ;
1730- yield * ( yield * GitVcsDriver . GitVcsDriver ) . prepareCommitContext ( cwd ) ;
1818+ yield * git ( cwd , [ "add" , "-A" ] ) ;
17311819 yield * ( yield * GitVcsDriver . GitVcsDriver ) . commit ( cwd , "Add feature" , "" ) ;
17321820
17331821 const pushed = yield * ( yield * GitVcsDriver . GitVcsDriver ) . pushCurrentBranch ( cwd , null ) ;
@@ -1799,7 +1887,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
17991887 yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
18001888 yield * git ( cwd , [ "push" , "-u" , "origin" , "main" ] ) ;
18011889 yield * writeTextFile ( cwd , "upstream.txt" , "upstream\n" ) ;
1802- yield * driver . prepareCommitContext ( cwd ) ;
1890+ yield * git ( cwd , [ "add" , "-A" ] ) ;
18031891 yield * driver . commit ( cwd , "Add upstream update" , "" ) ;
18041892
18051893 const pushed = yield * driver . pushCurrentBranch ( cwd , null ) ;
@@ -1840,7 +1928,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
18401928 const devSha = yield * git ( cwd , [ "rev-parse" , "HEAD" ] ) ;
18411929 yield * git ( cwd , [ "checkout" , "-b" , "feature/x" , "origin/dev" ] ) ;
18421930 yield * writeTextFile ( cwd , "feature.txt" , "feature\n" ) ;
1843- yield * driver . prepareCommitContext ( cwd ) ;
1931+ yield * git ( cwd , [ "add" , "-A" ] ) ;
18441932 yield * driver . commit ( cwd , "Add feature" , "" ) ;
18451933
18461934 const pushed = yield * driver . pushCurrentBranch ( cwd , null ) ;
@@ -1874,7 +1962,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
18741962 yield * git ( cwd , [ "checkout" , "-b" , "feature/y" , "origin/main" ] ) ;
18751963 yield * git ( cwd , [ "config" , "branch.feature/y.gh-merge-base" , "release/v2" ] ) ;
18761964 yield * writeTextFile ( cwd , "feature.txt" , "feature\n" ) ;
1877- yield * driver . prepareCommitContext ( cwd ) ;
1965+ yield * git ( cwd , [ "add" , "-A" ] ) ;
18781966 yield * driver . commit ( cwd , "Add feature" , "" ) ;
18791967
18801968 const pushed = yield * driver . pushCurrentBranch ( cwd , null ) ;
@@ -1912,7 +2000,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
19122000 "upstream/effect-atom" ,
19132001 ) ;
19142002 yield * writeTextFile ( cwd , "alias.txt" , "alias\n" ) ;
1915- yield * driver . prepareCommitContext ( cwd ) ;
2003+ yield * git ( cwd , [ "add" , "-A" ] ) ;
19162004 yield * driver . commit ( cwd , "Add alias update" , "" ) ;
19172005
19182006 const pushed = yield * driver . pushCurrentBranch ( cwd , null ) ;
0 commit comments