aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitsunyan2018-05-19 05:41:50 +0000
committerkitsunyan2018-05-19 05:41:50 +0000
commitf8107753a9a850bb86a2a8d07c71de082ea7a2c5 (patch)
tree26aaa499436f10caac3c8f24c0f326921ed4becc
parenta6c016ce89028d5195522a52f6dc0587c196fcb8 (diff)
Clone AUR repos without tags to user cache
-rw-r--r--src/common.nim33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/common.nim b/src/common.nim
index eb973c5..62966ee 100644
--- a/src/common.nim
+++ b/src/common.nim
@@ -8,7 +8,7 @@ type
repositories
BareKind* {.pure.} = enum
- repo
+ pkg, repo
SyncFoundPackageInfo* = tuple[
base: string,
@@ -625,19 +625,42 @@ proc cloneAurRepo*(config: Config, base: string, gitUrl: string,
dropPrivileges: bool): (int, Option[string]) =
let repoPath = repoPath(config.tmpRoot(dropPrivileges), base)
- let message = ensureTmpOrError(config, dropPrivileges)
+ let message = block:
+ let message = ensureUserCacheOrError(config, CacheKind.repositories, dropPrivileges)
+ if message.isNone:
+ ensureTmpOrError(config, dropPrivileges)
+ else:
+ message
+
if message.isSome:
(1, message)
elif repoPath.existsDir():
(0, none(string))
else:
- let cloneCode = forkWait(() => (block:
+ let fullName = bareFullName(BareKind.pkg, base)
+ let cachePath = config.userCache(dropPrivileges).cache(CacheKind.repositories)
+ let bareRepoPath = repoPath(cachePath, fullName)
+
+ let cloneBareCode = forkWait(() => (block:
if not dropPrivileges or dropPrivileges():
- execResult(gitCmd, "-C", config.tmpRoot(dropPrivileges),
- "clone", "-q", gitUrl, "--single-branch", base)
+ if existsDir(bareRepoPath):
+ execResult(gitCmd, "-C", bareRepoPath, "fetch", "-q", "--no-tags")
+ else:
+ execResult(gitCmd, "-C", cachePath, "clone", "-q", "--bare", "--no-tags",
+ gitUrl, "--single-branch", fullName)
else:
quit(1)))
+ let cloneCode = if cloneBareCode == 0:
+ forkWait(() => (block:
+ if not dropPrivileges or dropPrivileges():
+ execResult(gitCmd, "-C", config.tmpRoot(dropPrivileges),
+ "clone", "-q", bareRepoPath, "--single-branch", base)
+ else:
+ quit(1)))
+ else:
+ cloneBareCode
+
if cloneCode != 0:
(cloneCode, some(tr"$#: failed to clone git repository" % [base]))
else: