{"record":{"id":"1c408122c7015cac","repo":"GitoxideLabs/gitoxide","slug":"bug-this-method-may-only-be-called-until-it-is-su","errorCode":null,"errorMessage":"BUG: this method may only be called until it is successful","messagePattern":"BUG: this method may only be called until it is successful","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/clone/checkout.rs","lineNumber":94,"sourceCode":"            should_interrupt: &AtomicBool,\n        ) -> Result<(Repository, gix_worktree_state::checkout::Outcome), Error>\n        where\n            P: gix_features::progress::NestedProgress,\n            P::SubProgress: gix_features::progress::NestedProgress + 'static,\n        {\n            self.main_worktree_inner(&mut progress, should_interrupt)\n        }\n\n        fn main_worktree_inner(\n            &mut self,\n            progress: &mut dyn gix_features::progress::DynNestedProgress,\n            should_interrupt: &AtomicBool,\n        ) -> Result<(Repository, gix_worktree_state::checkout::Outcome), Error> {\n            let _span = gix_trace::coarse!(\"gix::clone::PrepareCheckout::main_worktree()\");\n            let repo = self\n                .repo\n                .as_ref()\n                .expect(\"BUG: this method may only be called until it is successful\");\n            let workdir = repo.workdir().ok_or_else(|| Error::BareRepository {\n                git_dir: repo.git_dir().to_owned(),\n            })?;\n\n            let root_tree_id = match &self.ref_name {\n                Some(reference_val) => Some(repo.find_reference(reference_val)?.peel_to_id()?),\n                None => repo.head()?.try_peel_to_id()?,\n            };\n\n            let root_tree = match root_tree_id {\n                Some(id) => id.object().expect(\"downloaded from remote\").peel_to_tree()?.id,\n                None => {\n                    return Ok((\n                        self.repo.take().expect(\"still present\"),\n                        gix_worktree_state::checkout::Outcome::default(),\n                    ));\n                }\n            };","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/clone/checkout.rs#L76-L112","documentation":"main_worktree_inner() asserts self.repo is still Some. PrepareCheckout owns the Repository in an Option and removes it once checkout succeeds and the repository is handed to the caller. Calling this method after a successful completion (or after persist/Drop consumed it) violates the type's state machine and panics.","triggerScenarios":"Calling main_worktree()/main_worktree_inner() a second time on the same PrepareCheckout value after a previous call succeeded and moved the repo out.","commonSituations":"Retry loops that re-invoke prepare without rebuilding it; code paths that continue after the value was consumed; misuse of the internal (crate-private) API during refactoring.","solutions":["Call main_worktree() exactly once; consume the returned Repository and never reuse the PrepareCheckout value.","Recreate the PrepareCheckout instance (via Clone::prepare_fetch/clone) if you need to retry checkout.","If you need the repository after success, use the Repository returned from the successful call."],"exampleFix":"// before\nlet repo1 = prepare.main_worktree(...)?;\nlet repo2 = prepare.main_worktree(...)?; // panics: already consumed\n// after\nlet repo = prepare.main_worktree(...)?;","handlingStrategy":"type-guard","validationCode":"// PrepareCheckout is crate-internal here; at the call site ensure main_worktree() is invoked once:\nassert!(!consumed, \"PrepareCheckout already completed\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call main_worktree() exactly once per PrepareCheckout.","Do not reuse the value in retry loops; construct a fresh PrepareCheckout instead.","Treat the success path as consuming the value (like persist())."],"tags":["rust","panic","state-machine","clone-checkout"],"backgroundTag":"invalid-state-transition","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}