sync: Fix committing when in a direct mode repo that has no HEAD ref.
Seen for example, a newly checked out git submodule. In this case, .git/HEAD is a raw sha, rather than the usual reference to a ref. Removed currentSha in passing, since it was a more roundabout way of doing what headSha does, and headSha is more robust.
This commit is contained in:
		
					parent
					
						
							
								79b6500111
							
						
					
				
			
			
				commit
				
					
						a6db10d565
					
				
			
		
					 5 changed files with 16 additions and 14 deletions
				
			
		| 
						 | 
					@ -13,8 +13,8 @@ import Config
 | 
				
			||||||
import Utility.Tmp
 | 
					import Utility.Tmp
 | 
				
			||||||
import Utility.Env
 | 
					import Utility.Env
 | 
				
			||||||
import Annex.Direct
 | 
					import Annex.Direct
 | 
				
			||||||
import qualified Git.Branch
 | 
					 | 
				
			||||||
import qualified Git.Sha
 | 
					import qualified Git.Sha
 | 
				
			||||||
 | 
					import qualified Git.Ref
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cmd :: [Command]
 | 
					cmd :: [Command]
 | 
				
			||||||
cmd = [notBareRepo $
 | 
					cmd = [notBareRepo $
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ start (c:ps) = liftIO . exitWith =<< ifM isDirect
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	go tmp = do
 | 
						go tmp = do
 | 
				
			||||||
		oldref <- fromMaybe Git.Sha.emptyTree
 | 
							oldref <- fromMaybe Git.Sha.emptyTree
 | 
				
			||||||
			<$> inRepo Git.Branch.currentSha
 | 
								<$> inRepo Git.Ref.headSha
 | 
				
			||||||
		exitcode <- liftIO $ proxy tmp
 | 
							exitcode <- liftIO $ proxy tmp
 | 
				
			||||||
		mergeDirectCleanup tmp oldref
 | 
							mergeDirectCleanup tmp oldref
 | 
				
			||||||
		return exitcode
 | 
							return exitcode
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,15 +174,15 @@ commitMsg = do
 | 
				
			||||||
	return $ "git-annex in " ++ fromMaybe "unknown" (M.lookup u m)
 | 
						return $ "git-annex in " ++ fromMaybe "unknown" (M.lookup u m)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
 | 
					commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
 | 
				
			||||||
commitStaged commitmode commitmessage = go =<< inRepo Git.Branch.currentUnsafe
 | 
					commitStaged commitmode commitmessage = do
 | 
				
			||||||
  where
 | 
						runAnnexHook preCommitAnnexHook
 | 
				
			||||||
	go Nothing = return False
 | 
						mb <- inRepo Git.Branch.currentUnsafe
 | 
				
			||||||
	go (Just branch) = do
 | 
						let (getparent, branch) = case mb of
 | 
				
			||||||
		runAnnexHook preCommitAnnexHook
 | 
							Just b -> (Git.Ref.sha b, b)
 | 
				
			||||||
		parent <- inRepo $ Git.Ref.sha branch
 | 
							Nothing -> (Git.Ref.headSha, Git.Ref.headRef)
 | 
				
			||||||
		void $ inRepo $ Git.Branch.commit commitmode False commitmessage branch
 | 
						parents <- maybeToList <$> inRepo getparent
 | 
				
			||||||
			(maybeToList parent)
 | 
						void $ inRepo $ Git.Branch.commit commitmode False commitmessage branch parents
 | 
				
			||||||
		return True
 | 
						return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mergeLocal :: Maybe Git.Ref -> CommandStart
 | 
					mergeLocal :: Maybe Git.Ref -> CommandStart
 | 
				
			||||||
mergeLocal Nothing = stop
 | 
					mergeLocal Nothing = stop
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,9 +43,6 @@ currentUnsafe r = parse . firstLine
 | 
				
			||||||
		| null l = Nothing
 | 
							| null l = Nothing
 | 
				
			||||||
		| otherwise = Just $ Git.Ref l
 | 
							| otherwise = Just $ Git.Ref l
 | 
				
			||||||
 | 
					
 | 
				
			||||||
currentSha :: Repo -> IO (Maybe Git.Sha)
 | 
					 | 
				
			||||||
currentSha r = maybe (pure Nothing) (`Git.Ref.sha` r) =<< current r
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{- Checks if the second branch has any commits not present on the first
 | 
					{- Checks if the second branch has any commits not present on the first
 | 
				
			||||||
 - branch. -}
 | 
					 - branch. -}
 | 
				
			||||||
changed :: Branch -> Branch -> Repo -> IO Bool
 | 
					changed :: Branch -> Branch -> Repo -> IO Bool
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,6 +88,9 @@ sha branch repo = process <$> showref repo
 | 
				
			||||||
	process [] = Nothing
 | 
						process [] = Nothing
 | 
				
			||||||
	process s = Just $ Ref $ firstLine s
 | 
						process s = Just $ Ref $ firstLine s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					headSha :: Repo -> IO (Maybe Sha)
 | 
				
			||||||
 | 
					headSha = sha headRef
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- List of (shas, branches) matching a given ref or refs. -}
 | 
					{- List of (shas, branches) matching a given ref or refs. -}
 | 
				
			||||||
matching :: [Ref] -> Repo -> IO [(Sha, Branch)]
 | 
					matching :: [Ref] -> Repo -> IO [(Sha, Branch)]
 | 
				
			||||||
matching refs repo =  matching' (map fromRef refs) repo
 | 
					matching refs repo =  matching' (map fromRef refs) repo
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								debian/changelog
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/changelog
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -27,6 +27,8 @@ git-annex (5.2015022) UNRELEASED; urgency=medium
 | 
				
			||||||
    (or '!') character.
 | 
					    (or '!') character.
 | 
				
			||||||
  * Also potentially fixes encoding problem when embedding credentials
 | 
					  * Also potentially fixes encoding problem when embedding credentials
 | 
				
			||||||
    that contain unicode characters.
 | 
					    that contain unicode characters.
 | 
				
			||||||
 | 
					  * sync: Fix committing when in a direct mode repo that has no HEAD ref.
 | 
				
			||||||
 | 
					    (For example, a newly checked out git submodule.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 -- Joey Hess <id@joeyh.name>  Thu, 19 Feb 2015 14:16:03 -0400
 | 
					 -- Joey Hess <id@joeyh.name>  Thu, 19 Feb 2015 14:16:03 -0400
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue