aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-04-25 06:02:46 +0000
committermerakor <cem@ckyln.com>2021-04-25 06:02:46 +0000
commit5c7f7d4c41d78c3a7ba986e65a697410ca0b219f (patch)
tree51d341e2aa445066c5aadb873c522b66025f1bf2 /src
parentbee7ea0d1268b64feba2f3cbbe811a7f7323ea7d (diff)
downloadcpt-5c7f7d4c41d78c3a7ba986e65a697410ca0b219f.tar.gz
pkg_repository_info: Add function that returns repository information
FossilOrigin-Name: 6e5c41e40438e00decab65e1dcbb577274f06069ba2b8dd5b4d124cd6dc2880b
Diffstat (limited to 'src')
-rw-r--r--src/cpt-lib.in43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index bf58fbe..2da51bb 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -1643,6 +1643,49 @@ pkg_install() {
log "$pkg_name" "Installed successfully"
}
+pkg_repository_info() {
+ # Finds and returns repository information for the current directory. It
+ # will return current directory, repository root, and the type of repository
+ # in a colon separated format.
+
+ if rootdir=$(git rev-parse --show-toplevel 2>/dev/null); then
+ # Git repository
+ backend=git
+
+ elif rootdir=$(hg root 2>/dev/null); then
+ # Mercurial repository
+ backend=hg
+
+ elif rootdir=$(fossil info 2>/dev/null | grep local-root:); then
+ # Fossil repository
+ backend=fossil
+
+ # We want to remove the initial spacing before the root directory.
+ read -r _ rootdir <<EOF
+$rootdir
+EOF
+ rootdir=${rootdir%/}
+
+ elif [ -f .rsync ]; then
+ backend=rsync
+ rootdir=$PWD
+
+ # If an .rsync_root file exists, we check that the repository root
+ # exists. If it does, we change to that directory to do the fetch.
+ # This way, we allow for partial repositories while making sure that
+ # we can fetch the repository in a single operation.
+ [ -f .rsync_root ] && {
+ read -r rsync_root < .rsync_root
+ [ -f "$rsync_root/.rsync" ] && rootdir=$(_readlinkf "$rsync_root")
+ }
+ else
+ # Local repository
+ backend=local
+ rootdir=$PWD
+ fi
+ printf '%s:%s:%s\n' "$PWD" "$rootdir" "$backend"
+}
+
pkg_fetch() {
log "Updating repositories"