work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about pushing into the currently checked out branch doesn't work. A simple fix for this would be an update hook which blocks the pushes.. but git hooks must be executable, and git-annex needs to be usable on eg, FAT, which lacks x bits. Instead, enabling direct mode switches the branch (eg master) to a special purpose branch (eg annex/direct/master). This branch is not pushed when syncing; instead any changes that git annex sync commits get written to master, and it's pushed (along with synced/master) to the remote. Note that initialization has been changed to always call setDirect, even if it's just setDirect False for indirect mode. This is needed because if the user has just cloned a direct mode repo, that nothing has synced with before, it may have no master branch, and only a annex/direct/master. Resulting in that branch being checked out locally too. Calling setDirect False for indirect mode moves back out of this branch, to a new master branch, and ensures that a manual "git push" doesn't push changes directly to the annex/direct/master of the remote. (It's possible that the user makes a commit w/o using git-annex and pushes it, but nothing I can do about that really.) This commit was sponsored by Jonathan Harrington.
This commit is contained in:
parent
cf34e59c8c
commit
3802f2f270
6 changed files with 126 additions and 48 deletions
|
@ -13,7 +13,7 @@ import Common
|
|||
import Git
|
||||
import Git.Sha
|
||||
import Git.Command
|
||||
import Git.Ref (headRef)
|
||||
import qualified Git.Ref
|
||||
|
||||
{- The currently checked out branch.
|
||||
-
|
||||
|
@ -36,7 +36,7 @@ current r = do
|
|||
{- The current branch, which may not really exist yet. -}
|
||||
currentUnsafe :: Repo -> IO (Maybe Git.Ref)
|
||||
currentUnsafe r = parse . firstLine
|
||||
<$> pipeReadStrict [Param "symbolic-ref", Param $ show headRef] r
|
||||
<$> pipeReadStrict [Param "symbolic-ref", Param $ show Git.Ref.headRef] r
|
||||
where
|
||||
parse l
|
||||
| null l = Nothing
|
||||
|
@ -113,3 +113,21 @@ update branch sha = run
|
|||
, Param $ show branch
|
||||
, Param $ show sha
|
||||
]
|
||||
|
||||
{- Checks out a branch, creating it if necessary. -}
|
||||
checkout :: Branch -> Repo -> IO ()
|
||||
checkout branch = run
|
||||
[ Param "checkout"
|
||||
, Param "-q"
|
||||
, Param "-B"
|
||||
, Param $ show $ Git.Ref.base branch
|
||||
]
|
||||
|
||||
{- Removes a branch. -}
|
||||
delete :: Branch -> Repo -> IO ()
|
||||
delete branch = run
|
||||
[ Param "branch"
|
||||
, Param "-q"
|
||||
, Param "-D"
|
||||
, Param $ show $ Git.Ref.base branch
|
||||
]
|
||||
|
|
10
Git/Ref.hs
10
Git/Ref.hs
|
@ -29,11 +29,17 @@ base = Ref . remove "refs/heads/" . remove "refs/remotes/" . show
|
|||
| prefix `isPrefixOf` s = drop (length prefix) s
|
||||
| otherwise = s
|
||||
|
||||
{- Given a directory and any ref, takes the basename of the ref and puts
|
||||
- it under the directory. -}
|
||||
under :: String -> Ref -> Ref
|
||||
under dir r = Ref $ dir ++ "/" ++
|
||||
(reverse $ takeWhile (/= '/') $ reverse $ show r)
|
||||
|
||||
{- Given a directory such as "refs/remotes/origin", and a ref such as
|
||||
- refs/heads/master, yields a version of that ref under the directory,
|
||||
- such as refs/remotes/origin/master. -}
|
||||
under :: String -> Ref -> Ref
|
||||
under dir r = Ref $ dir </> show (base r)
|
||||
underBase :: String -> Ref -> Ref
|
||||
underBase dir r = Ref $ dir ++ "/" ++ show (base r)
|
||||
|
||||
{- Checks if a ref exists. -}
|
||||
exists :: Ref -> Repo -> IO Bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue