@@ -4547,6 +4547,60 @@ def test_checkout_to_commit_sha(self) -> None:
45474547 porcelain .checkout (self .repo , self ._sha )
45484548 self .assertEqual (self ._sha , self .repo .head ())
45494549
4550+ # Working tree and index should be clean after checkout
4551+ status = list (porcelain .status (self .repo ))
4552+ self .assertEqual ([{"add" : [], "delete" : [], "modify" : []}, [], []], status )
4553+
4554+ def test_checkout_files_starting_with_dotgit (self ) -> None :
4555+ # Regression test: paths starting with ".git" (like .github/, .gitignore,
4556+ # .gitattributes) were incorrectly skipped during checkout, leaving the
4557+ # index out of sync with HEAD.
4558+ github_dir = os .path .join (self .repo .path , ".github" , "workflows" )
4559+ os .makedirs (github_dir )
4560+
4561+ github_file = os .path .join (github_dir , "ci.yml" )
4562+ gitignore_file = os .path .join (self .repo .path , ".gitignore" )
4563+
4564+ with open (github_file , "w" ) as f :
4565+ f .write ("# version 1\n " )
4566+ with open (gitignore_file , "w" ) as f :
4567+ f .write ("*.pyc\n " )
4568+
4569+ porcelain .add (self .repo , paths = [github_file , gitignore_file ])
4570+ sha1 = porcelain .commit (
4571+ self .repo ,
4572+ message = b"add .github and .gitignore" ,
4573+ committer = b"Jane <jane@example.com>" ,
4574+ author = b"John <john@example.com>" ,
4575+ )
4576+
4577+ # Update those files in a second commit
4578+ with open (github_file , "w" ) as f :
4579+ f .write ("# version 2\n " )
4580+ with open (gitignore_file , "w" ) as f :
4581+ f .write ("*.pyc\n *.pyo\n " )
4582+
4583+ porcelain .add (self .repo , paths = [github_file , gitignore_file ])
4584+ porcelain .commit (
4585+ self .repo ,
4586+ message = b"update .github and .gitignore" ,
4587+ committer = b"Jane <jane@example.com>" ,
4588+ author = b"John <john@example.com>" ,
4589+ )
4590+
4591+ # Checkout the first commit (going back to v1)
4592+ porcelain .checkout (self .repo , sha1 )
4593+
4594+ # Working tree and index should be clean (no staged changes)
4595+ status = list (porcelain .status (self .repo ))
4596+ self .assertEqual ([{"add" : [], "delete" : [], "modify" : []}, [], []], status )
4597+
4598+ # Working tree files should have v1 content
4599+ with open (github_file ) as f :
4600+ self .assertEqual ("# version 1\n " , f .read ())
4601+ with open (gitignore_file ) as f :
4602+ self .assertEqual ("*.pyc\n " , f .read ())
4603+
45504604 def test_checkout_to_head (self ) -> None :
45514605 new_sha = self ._commit_something_wrong ()
45524606
0 commit comments