summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
Diffstat (limited to 'Git')
-rw-r--r--Git/GCrypt.hs19
-rw-r--r--Git/Remote.hs19
2 files changed, 36 insertions, 2 deletions
diff --git a/Git/GCrypt.hs b/Git/GCrypt.hs
index 1260c2ced..c8c193c45 100644
--- a/Git/GCrypt.hs
+++ b/Git/GCrypt.hs
@@ -13,6 +13,7 @@ import Common
import Git.Types
import Git.Construct
import qualified Git.Config as Config
+import qualified Git.Command as Command
import Utility.Gpg
urlPrefix :: String
@@ -44,12 +45,28 @@ encryptedRepo baserepo = go
go _ = notencrypted
notencrypted = error "not a gcrypt encrypted repository"
+{- Checks if the git repo at a location is a gcrypt repo that
+ - we can decrypt. This works by trying to fetch from the repo
+ - at the location, into the baserepo.
+ -
+ - Returns false if the git repo is not using gcrypt, or if it is using
+ - gcrypt but cannot be decrypted. We do not try to detect gcrypt
+ - repos that cannot be decrypted, because gcrypt may change in the future
+ - to avoid easy fingerprinting of gcrypt repos.
+ -}
+probeGCryptRepo :: FilePath -> Repo -> IO Bool
+probeGCryptRepo dir baserepo = catchBoolIO $ Command.runBool
+ [ Param "fetch"
+ , Param $ urlPrefix ++ dir
+ ] baserepo
+
type RemoteName = String
+type GCryptId = String
{- gcrypt gives each encrypted repository a uique gcrypt-id,
- which is stored in the repository (in encrypted form)
- and cached in a per-remote gcrypt-id configuration setting. -}
-remoteRepoId :: Repo -> Maybe RemoteName -> Maybe String
+remoteRepoId :: Repo -> Maybe RemoteName -> Maybe GCryptId
remoteRepoId = getRemoteConfig "gcrypt-id"
getRemoteConfig :: String -> Repo -> Maybe RemoteName -> Maybe String
diff --git a/Git/Remote.hs b/Git/Remote.hs
index 5640e9ff2..e853e53cb 100644
--- a/Git/Remote.hs
+++ b/Git/Remote.hs
@@ -8,15 +8,21 @@
module Git.Remote where
import Common
+import Git
+import qualified Git.Command
+import qualified Git.BuildVersion
+
import Data.Char
+type RemoteName = String
+
{- Construct a legal git remote name out of an arbitrary input string.
-
- There seems to be no formal definition of this in the git source,
- just some ad-hoc checks, and some other things that fail with certian
- types of names (like ones starting with '-').
-}
-makeLegalName :: String -> String
+makeLegalName :: String -> RemoteName
makeLegalName s = case filter legal $ replace "/" "_" s of
-- it can't be empty
[] -> "unnamed"
@@ -31,3 +37,14 @@ makeLegalName s = case filter legal $ replace "/" "_" s of
legal '_' = True
legal '.' = True
legal c = isAlphaNum c
+
+remove :: RemoteName -> Repo -> IO ()
+remove remotename = Git.Command.run
+ [ Param "remote"
+ -- name of this subcommand changed
+ , Param $
+ if Git.BuildVersion.older "1.8.0"
+ then "rm"
+ else "remove"
+ , Param remotename
+ ]