Commit and push uncommitted changes on startup
- watchRepo: call syncRepo at startup to commit any pre-existing uncommitted changes before entering the file watcher - Add gitPush function for git push <remote> <branch> - Add push step to syncRepo after successful pull (with failure notification via notifyUser) - Export syncRepo and gitPush for testing - Test: startup sync commits and pushes uncommitted changes
This commit is contained in:
+26
-1
@@ -1,6 +1,6 @@
|
||||
module GitCommitSpec (spec) where
|
||||
|
||||
import Converge (gitCommitAll)
|
||||
import Converge (Options (..), RepoConfig (..), defaultOptions, defaultRepoConfig, gitCommitAll, syncRepo)
|
||||
import qualified Data.Text as T
|
||||
import System.Exit (ExitCode (..))
|
||||
import System.FilePath ((</>))
|
||||
@@ -55,3 +55,28 @@ spec = do
|
||||
code2 `shouldSatisfy` (/= ExitSuccess)
|
||||
countAfter2 <- commitCount repo
|
||||
countAfter2 `shouldBe` countBefore2
|
||||
|
||||
describe "startup sync" $ do
|
||||
|
||||
it "commits and pushes uncommitted changes on startup" $ do
|
||||
logger <- testLogger
|
||||
withTempGitRepoWithRemote $ \repo -> do
|
||||
-- Leave a file uncommitted (simulating state before converge starts)
|
||||
writeFile (repo </> "uncommitted.txt") "pending change"
|
||||
|
||||
countBefore <- commitCount repo
|
||||
countBefore `shouldBe` 1
|
||||
|
||||
let cfg = defaultRepoConfig {rcPath = repo}
|
||||
let opts = defaultOptions
|
||||
{ optRepos = [cfg]
|
||||
, optNotifyCmd = "true" -- avoid firing notify-send
|
||||
}
|
||||
syncRepo opts logger cfg
|
||||
|
||||
countAfter <- commitCount repo
|
||||
countAfter `shouldBe` 2
|
||||
|
||||
-- Verify the commit was pushed to remote
|
||||
(_, remoteLog, _) <- runGitIn repo ["log", "origin/main", "--oneline", "--name-only"]
|
||||
remoteLog `shouldSatisfy` ("uncommitted.txt" `T.isInfixOf`)
|
||||
|
||||
Reference in New Issue
Block a user