reinit: New command that can initialize a new reposotory using the configuration of a previously known repository. Useful if a repository got deleted and you want to clone it back the way it was.
This commit is contained in:
parent
162565d928
commit
915d038bec
8 changed files with 81 additions and 11 deletions
|
@ -11,6 +11,7 @@ module Annex.Init (
|
||||||
ensureInitialized,
|
ensureInitialized,
|
||||||
isInitialized,
|
isInitialized,
|
||||||
initialize,
|
initialize,
|
||||||
|
initialize',
|
||||||
uninitialize,
|
uninitialize,
|
||||||
probeCrippledFileSystem,
|
probeCrippledFileSystem,
|
||||||
) where
|
) where
|
||||||
|
@ -60,6 +61,17 @@ genDescription Nothing = do
|
||||||
initialize :: Maybe String -> Annex ()
|
initialize :: Maybe String -> Annex ()
|
||||||
initialize mdescription = do
|
initialize mdescription = do
|
||||||
prepUUID
|
prepUUID
|
||||||
|
initialize'
|
||||||
|
|
||||||
|
u <- getUUID
|
||||||
|
{- This will make the first commit to git, so ensure git is set up
|
||||||
|
- properly to allow commits when running it. -}
|
||||||
|
ensureCommit $ do
|
||||||
|
Annex.Branch.create
|
||||||
|
describeUUID u =<< genDescription mdescription
|
||||||
|
|
||||||
|
initialize' :: Annex ()
|
||||||
|
initialize' = do
|
||||||
checkFifoSupport
|
checkFifoSupport
|
||||||
checkCrippledFileSystem
|
checkCrippledFileSystem
|
||||||
unlessM isBare $
|
unlessM isBare $
|
||||||
|
@ -75,12 +87,6 @@ initialize mdescription = do
|
||||||
switchHEADBack
|
switchHEADBack
|
||||||
)
|
)
|
||||||
createInodeSentinalFile
|
createInodeSentinalFile
|
||||||
u <- getUUID
|
|
||||||
{- This will make the first commit to git, so ensure git is set up
|
|
||||||
- properly to allow commits when running it. -}
|
|
||||||
ensureCommit $ do
|
|
||||||
Annex.Branch.create
|
|
||||||
describeUUID u =<< genDescription mdescription
|
|
||||||
|
|
||||||
uninitialize :: Annex ()
|
uninitialize :: Annex ()
|
||||||
uninitialize = do
|
uninitialize = do
|
||||||
|
|
|
@ -21,6 +21,7 @@ module Annex.UUID (
|
||||||
gCryptNameSpace,
|
gCryptNameSpace,
|
||||||
removeRepoUUID,
|
removeRepoUUID,
|
||||||
storeUUID,
|
storeUUID,
|
||||||
|
storeUUIDIn,
|
||||||
setUUID,
|
setUUID,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ getRepoUUID r = do
|
||||||
where
|
where
|
||||||
updatecache u = do
|
updatecache u = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
when (g /= r) $ storeUUID cachekey u
|
when (g /= r) $ storeUUIDIn cachekey u
|
||||||
cachekey = remoteConfig r "uuid"
|
cachekey = remoteConfig r "uuid"
|
||||||
|
|
||||||
removeRepoUUID :: Annex ()
|
removeRepoUUID :: Annex ()
|
||||||
|
@ -84,10 +85,13 @@ getUncachedUUID = toUUID . Git.Config.get key ""
|
||||||
{- Make sure that the repo has an annex.uuid setting. -}
|
{- Make sure that the repo has an annex.uuid setting. -}
|
||||||
prepUUID :: Annex ()
|
prepUUID :: Annex ()
|
||||||
prepUUID = whenM ((==) NoUUID <$> getUUID) $
|
prepUUID = whenM ((==) NoUUID <$> getUUID) $
|
||||||
storeUUID configkey =<< liftIO genUUID
|
storeUUID =<< liftIO genUUID
|
||||||
|
|
||||||
storeUUID :: ConfigKey -> UUID -> Annex ()
|
storeUUID :: UUID -> Annex ()
|
||||||
storeUUID configfield = setConfig configfield . fromUUID
|
storeUUID = storeUUIDIn configkey
|
||||||
|
|
||||||
|
storeUUIDIn :: ConfigKey -> UUID -> Annex ()
|
||||||
|
storeUUIDIn configfield = setConfig configfield . fromUUID
|
||||||
|
|
||||||
{- Only sets the configkey in the Repo; does not change .git/config -}
|
{- Only sets the configkey in the Repo; does not change .git/config -}
|
||||||
setUUID :: Git.Repo -> UUID -> IO Git.Repo
|
setUUID :: Git.Repo -> UUID -> IO Git.Repo
|
||||||
|
|
|
@ -74,7 +74,7 @@ makeXMPPGitRemote :: String -> JID -> UUID -> Assistant Bool
|
||||||
makeXMPPGitRemote buddyname jid u = do
|
makeXMPPGitRemote buddyname jid u = do
|
||||||
remote <- liftAnnex $ addRemote $
|
remote <- liftAnnex $ addRemote $
|
||||||
makeGitRemote buddyname $ gitXMPPLocation jid
|
makeGitRemote buddyname $ gitXMPPLocation jid
|
||||||
liftAnnex $ storeUUID (remoteConfig (Remote.repo remote) "uuid") u
|
liftAnnex $ storeUUIDIn (remoteConfig (Remote.repo remote) "uuid") u
|
||||||
liftAnnex $ void remoteListRefresh
|
liftAnnex $ void remoteListRefresh
|
||||||
remote' <- liftAnnex $ fromMaybe (error "failed to add remote")
|
remote' <- liftAnnex $ fromMaybe (error "failed to add remote")
|
||||||
<$> Remote.byName (Just buddyname)
|
<$> Remote.byName (Just buddyname)
|
||||||
|
|
|
@ -57,6 +57,7 @@ import qualified Command.Info
|
||||||
import qualified Command.Status
|
import qualified Command.Status
|
||||||
import qualified Command.Migrate
|
import qualified Command.Migrate
|
||||||
import qualified Command.Uninit
|
import qualified Command.Uninit
|
||||||
|
import qualified Command.Reinit
|
||||||
import qualified Command.NumCopies
|
import qualified Command.NumCopies
|
||||||
import qualified Command.Trust
|
import qualified Command.Trust
|
||||||
import qualified Command.Untrust
|
import qualified Command.Untrust
|
||||||
|
@ -125,6 +126,7 @@ cmds = concat
|
||||||
, Command.Reinject.def
|
, Command.Reinject.def
|
||||||
, Command.Unannex.def
|
, Command.Unannex.def
|
||||||
, Command.Uninit.def
|
, Command.Uninit.def
|
||||||
|
, Command.Reinit.def
|
||||||
, Command.PreCommit.def
|
, Command.PreCommit.def
|
||||||
, Command.NumCopies.def
|
, Command.NumCopies.def
|
||||||
, Command.Trust.def
|
, Command.Trust.def
|
||||||
|
|
38
Command/Reinit.hs
Normal file
38
Command/Reinit.hs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{- git-annex command
|
||||||
|
-
|
||||||
|
- Copyright 2014 Joey Hess <joey@kitenet.net>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Command.Reinit where
|
||||||
|
|
||||||
|
import Common.Annex
|
||||||
|
import Command
|
||||||
|
import Annex.Init
|
||||||
|
import Annex.UUID
|
||||||
|
import Types.UUID
|
||||||
|
import qualified Remote
|
||||||
|
|
||||||
|
def :: [Command]
|
||||||
|
def = [dontCheck repoExists $
|
||||||
|
command "reinit" (paramUUID ++ " or " ++ paramDesc) seek SectionUtility ""]
|
||||||
|
|
||||||
|
seek :: CommandSeek
|
||||||
|
seek = withWords start
|
||||||
|
|
||||||
|
start :: [String] -> CommandStart
|
||||||
|
start ws = do
|
||||||
|
showStart "reinit" s
|
||||||
|
next $ perform s
|
||||||
|
where
|
||||||
|
s = unwords ws
|
||||||
|
|
||||||
|
perform :: String -> CommandPerform
|
||||||
|
perform s = do
|
||||||
|
u <- if isUUID s
|
||||||
|
then return $ toUUID s
|
||||||
|
else Remote.nameToUUID s
|
||||||
|
storeUUID u
|
||||||
|
initialize'
|
||||||
|
next $ return True
|
|
@ -8,6 +8,8 @@
|
||||||
module Types.UUID where
|
module Types.UUID where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import qualified Data.UUID as U
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
|
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
|
||||||
data UUID = NoUUID | UUID String
|
data UUID = NoUUID | UUID String
|
||||||
|
@ -21,4 +23,7 @@ toUUID :: String -> UUID
|
||||||
toUUID [] = NoUUID
|
toUUID [] = NoUUID
|
||||||
toUUID s = UUID s
|
toUUID s = UUID s
|
||||||
|
|
||||||
|
isUUID :: String -> Bool
|
||||||
|
isUUID = isJust . U.fromString
|
||||||
|
|
||||||
type UUIDMap = M.Map UUID String
|
type UUIDMap = M.Map UUID String
|
||||||
|
|
4
debian/changelog
vendored
4
debian/changelog
vendored
|
@ -17,6 +17,10 @@ git-annex (5.20140413) UNRELEASED; urgency=medium
|
||||||
* Avoid depending on shakespeare except for when building the webapp.
|
* Avoid depending on shakespeare except for when building the webapp.
|
||||||
* uninit: Avoid making unncessary copies of files.
|
* uninit: Avoid making unncessary copies of files.
|
||||||
* info: Allow use in a repository where annex.uuid is not set.
|
* info: Allow use in a repository where annex.uuid is not set.
|
||||||
|
* reinit: New command that can initialize a new reposotory using
|
||||||
|
the configuration of a previously known repository.
|
||||||
|
Useful if a repository got deleted and you want
|
||||||
|
to clone it back the way it was.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 21:33:35 -0400
|
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 21:33:35 -0400
|
||||||
|
|
||||||
|
|
|
@ -845,6 +845,17 @@ subdirectories).
|
||||||
repository, and remove all of git-annex's other data, leaving you with a
|
repository, and remove all of git-annex's other data, leaving you with a
|
||||||
git repository plus the previously annexed files.
|
git repository plus the previously annexed files.
|
||||||
|
|
||||||
|
* `reinit uuid|description`
|
||||||
|
|
||||||
|
Normally, initializing a repository generates a new, unique identifier
|
||||||
|
(UUID) for that repository. Occasionally it may be useful to reuse a
|
||||||
|
UUID -- for example, if a repository got deleted, and you're
|
||||||
|
setting it back up.
|
||||||
|
|
||||||
|
Use this with caution; it can be confusing to have two existing
|
||||||
|
repositories with the same UUID. Also, you will probably want to run
|
||||||
|
a fsck.
|
||||||
|
|
||||||
# PLUMBING COMMANDS
|
# PLUMBING COMMANDS
|
||||||
|
|
||||||
* `pre-commit [path ...]`
|
* `pre-commit [path ...]`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue