@@ -7,7 +7,14 @@ import { runCommandExitCode } from "../shell/command-runner.js"
77import { CommandFailedError } from "../shell/errors.js"
88import { defaultProjectsRoot } from "./menu-helpers.js"
99import { adoptRemoteHistoryIfOrphan } from "./state-repo/adopt-remote.js"
10- import { autoSyncEnvKey , autoSyncStrictEnvKey , isAutoSyncEnabled , isTruthyEnv } from "./state-repo/env.js"
10+ import {
11+ autoPullEnvKey ,
12+ autoSyncEnvKey ,
13+ autoSyncStrictEnvKey ,
14+ isAutoPullEnabled ,
15+ isAutoSyncEnabled ,
16+ isTruthyEnv
17+ } from "./state-repo/env.js"
1118import {
1219 git ,
1320 gitBaseEnv ,
@@ -134,6 +141,58 @@ export const autoSyncState = (message: string): Effect.Effect<void, never, State
134141 Effect . asVoid
135142 )
136143
144+ // CHANGE: add autoPullState to perform git pull on .docker-git at startup
145+ // WHY: ensure local .docker-git state is up-to-date every time the docker-git command runs
146+ // QUOTE(ТЗ): "Сделать что бы когда вызывается команда docker-git то происходит git pull для .docker-git папки"
147+ // REF: issue-178
148+ // PURITY: SHELL
149+ // EFFECT: Effect<void, never, StateRepoEnv>
150+ // INVARIANT: never fails — errors are logged as warnings; does not block CLI execution
151+ // COMPLEXITY: O(1) network round-trip
152+ export const autoPullState : Effect . Effect < void , never , StateRepoEnv > = Effect . gen ( function * ( _ ) {
153+ const path = yield * _ ( Path . Path )
154+ const root = resolveStateRoot ( path , process . cwd ( ) )
155+ const repoOk = yield * _ ( isGitRepo ( root ) )
156+ if ( ! repoOk ) {
157+ return
158+ }
159+ const originOk = yield * _ ( hasOriginRemote ( root ) )
160+ const enabled = isAutoPullEnabled ( process . env [ autoPullEnvKey ] , originOk )
161+ if ( ! enabled ) {
162+ return
163+ }
164+ yield * _ ( statePullInternal ( root ) )
165+ } ) . pipe (
166+ Effect . matchEffect ( {
167+ onFailure : ( error ) => Effect . logWarning ( `State auto-pull failed: ${ String ( error ) } ` ) ,
168+ onSuccess : ( ) => Effect . void
169+ } ) ,
170+ Effect . asVoid
171+ )
172+
173+ // Internal pull that takes an already-resolved root, reusing auth logic from pull-push.
174+ const statePullInternal = (
175+ root : string
176+ ) : Effect . Effect < void , CommandFailedError | PlatformError , StateRepoEnv > =>
177+ Effect . gen ( function * ( _ ) {
178+ const fs = yield * _ ( FileSystem . FileSystem )
179+ const path = yield * _ ( Path . Path )
180+ const originUrlExit = yield * _ ( gitExitCode ( root , [ "remote" , "get-url" , "origin" ] , gitBaseEnv ) )
181+ if ( originUrlExit !== successExitCode ) {
182+ yield * _ ( git ( root , [ "pull" , "--rebase" ] , gitBaseEnv ) )
183+ return
184+ }
185+ const rawOriginUrl = yield * _ (
186+ gitCapture ( root , [ "remote" , "get-url" , "origin" ] , gitBaseEnv ) . pipe ( Effect . map ( ( value ) => value . trim ( ) ) )
187+ )
188+ const originUrl = yield * _ ( normalizeOriginUrlIfNeeded ( root , rawOriginUrl ) )
189+ const token = yield * _ ( resolveGithubToken ( fs , path , root ) )
190+ const effect = token && token . length > 0 && isGithubHttpsRemote ( originUrl )
191+ ? withGithubAskpassEnv ( token , ( env ) => git ( root , [ "pull" , "--rebase" ] , env ) )
192+ : git ( root , [ "pull" , "--rebase" ] , gitBaseEnv )
193+ yield * _ ( effect )
194+ } ) . pipe ( Effect . asVoid )
195+
137196type StateInitInput = {
138197 readonly repoUrl : string
139198 readonly repoRef : string
0 commit comments