summaryrefslogtreecommitdiff
path: root/Init.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-03 10:45:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-03 10:45:18 -0400
commitabde98cda21d5deeb16ed3baf736b06fdc2fce2f (patch)
tree4f02c3d91ad4fbd24eb0f8faa5f437d02231ebc9 /Init.hs
parent3f74377b93f6147036061400b3697a665a337e64 (diff)
init: If no description is provided for a new repository, one will automatically be generated, like "joey@gnu:~/foo"
Diffstat (limited to 'Init.hs')
-rw-r--r--Init.hs22
1 files changed, 21 insertions, 1 deletions
diff --git a/Init.hs b/Init.hs
index bddcc696e..291e346f5 100644
--- a/Init.hs
+++ b/Init.hs
@@ -19,6 +19,26 @@ import Logs.UUID
import Annex.Version
import Annex.UUID
+import System.Posix.User
+
+genDescription :: Maybe String -> Annex String
+genDescription (Just d) = return d
+genDescription Nothing = do
+ hostname <- getHostname
+ let at = if null hostname then "" else "@"
+ username <- clicketyclickety
+ reldir <- liftIO . relHome =<< fromRepo Git.repoPath
+ return $ concat [username, at, hostname, ":", reldir]
+ where
+ {- Haskell lacks uname(2) bindings, except in the
+ - Bindings.Uname addon. Rather than depend on that,
+ - use uname -n when available. -}
+ getHostname = liftIO $ catchDefaultIO uname_node ""
+ uname_node = takeWhile (/= '\n') <$>
+ readProcess "uname" ["-n"]
+ clicketyclickety = liftIO $ userName <$>
+ (getUserEntryForID =<< getEffectiveUserID)
+
initialize :: Maybe String -> Annex ()
initialize mdescription = do
prepUUID
@@ -26,7 +46,7 @@ initialize mdescription = do
setVersion
gitPreCommitHookWrite
u <- getUUID
- maybe (recordUUID u) (describeUUID u) mdescription
+ describeUUID u =<< genDescription mdescription
uninitialize :: Annex ()
uninitialize = do