pgit.sh: Auto-detect current project in toplevel dir

This commit allows pgit.sh to target not only multiple projects below
a projects-directory, but also one single project. If invoked from
the toplevel directory of a project, it uses that as the only project
it should deal with. This is meant to facilitate running the same VCS
abstraction logic for one project as for many projects. The project
or projects to deal with should probably be specified on the command
line, but changing the auto-detection mechanism buys us what we want
for now with low hassle.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-17 17:19:46 +01:00
commit cb3ccaa338

View file

@ -39,10 +39,14 @@ set_global_variables()
{
[ "$projects_dir" ] || {
projects_dir=`pwd`
# If we're in a toplevel directory, suppose projects_dir == project_dirs,
# i.e. we only want to target this Git repo
if [ ! -d .git ]; then
while [ ! -r Makefile ] || ! grep -q some-random-string-to-id-this-makefile Makefile; do
[ "$projects_dir" = / ] && fatal "Failed to find projects directory"
projects_dir=`dirname $projects_dir`
done
fi
}
[ "$project_dirs" ] || {