git-annex/git-union-merge.hs

49 lines
1.1 KiB
Haskell
Raw Normal View History

{- git-union-merge program
-
- Copyright 2011 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
import System.Environment
import Common
import qualified Git.UnionMerge
import qualified Git.Config
import qualified Git.CurrentRepo
2011-12-13 19:22:43 +00:00
import qualified Git.Branch
2011-12-14 19:30:14 +00:00
import qualified Git.Index
import qualified Git
header :: String
2011-06-21 02:21:02 +00:00
header = "Usage: git-union-merge ref ref newref"
usage :: IO a
usage = error $ "bad parameters\n\n" ++ header
2011-06-21 20:08:09 +00:00
tmpIndex :: Git.Repo -> FilePath
Clean up handling of git directory and git worktree. Baked into the code was an assumption that a repository's git directory could be determined by adding ".git" to its work tree (or nothing for bare repos). That fails when core.worktree, or GIT_DIR and GIT_WORK_TREE are used to separate the two. This was attacked at the type level, by storing the gitdir and worktree separately, so Nothing for the worktree means a bare repo. A complication arose because we don't learn where a repository is bare until its configuration is read. So another Location type handles repositories that have not had their config read yet. I am not entirely happy with this being a Location type, rather than representing them entirely separate from the Git type. The new code is not worse than the old, but better types could enforce more safety. Added support for core.worktree. Overriding it with -c isn't supported because it's not really clear what to do if a git repo's config is read, is not bare, and is then overridden to bare. What is the right git directory in this case? I will worry about this if/when someone has a use case for overriding core.worktree with -c. (See Git.Config.updateLocation) Also removed and renamed some functions like gitDir and workTree that misused git's terminology. One minor regression is known: git annex add in a bare repository does not print a nice error message, but runs git ls-files in a way that fails earlier with a less nice error message. This is because before --work-tree was always passed to git commands, even in a bare repo, while now it's not.
2012-05-18 20:38:26 +00:00
tmpIndex g = Git.localGitDir g </> "index.git-union-merge"
2011-06-21 20:08:09 +00:00
setup :: Git.Repo -> IO ()
2011-09-21 03:24:48 +00:00
setup = cleanup -- idempotency
2011-06-21 20:08:09 +00:00
cleanup :: Git.Repo -> IO ()
2012-06-06 17:13:13 +00:00
cleanup g = nukeFile $ tmpIndex g
2011-06-21 20:08:09 +00:00
parseArgs :: IO [String]
parseArgs = do
args <- getArgs
if length args /= 3
then usage
else return args
2011-06-21 18:09:06 +00:00
main :: IO ()
main = do
[aref, bref, newref] <- map Git.Ref <$> parseArgs
g <- Git.Config.read =<< Git.CurrentRepo.get
_ <- Git.Index.override (tmpIndex g) g
setup g
Git.UnionMerge.merge aref bref g
2016-03-14 20:19:27 +00:00
_ <- Git.Branch.commit Git.Branch.ManualCommit False "union merge" newref [aref, bref] g
cleanup g