From 5c7f7d4c41d78c3a7ba986e65a697410ca0b219f Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 25 Apr 2021 06:02:46 +0000 Subject: pkg_repository_info: Add function that returns repository information FossilOrigin-Name: 6e5c41e40438e00decab65e1dcbb577274f06069ba2b8dd5b4d124cd6dc2880b --- src/cpt-lib.in | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src') 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 <