From fd1f593ac86e95bd7a4f189be2d38d8f79da1a13 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sat, 26 Jul 2025 13:36:08 +0200 Subject: [PATCH] build: Make {aosp,clo}remote work when not in the root dir of the repo Change-Id: I59dcfb7a7c50ad5ae70b3823cea50b3cbf4671d6 --- build/envsetup.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/build/envsetup.sh b/build/envsetup.sh index 7cc8f665..1f38a186 100644 --- a/build/envsetup.sh +++ b/build/envsetup.sh @@ -246,15 +246,16 @@ function lineageremote() function aospremote() { - if ! git rev-parse --git-dir &> /dev/null + local T=`git rev-parse --show-toplevel 2> /dev/null` + if [ -z "$T" ] then - echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." + echo "Git repository not found. Please run this from the directory of the Android repository you wish to set up." return 1 fi git remote rm aosp 2> /dev/null - if [ -f ".gitupstream" ]; then - local REMOTE=$(cat .gitupstream | cut -d ' ' -f 1) + if [ -f "$T/.gitupstream" ]; then + local REMOTE=$(cat "$T/.gitupstream" | cut -d ' ' -f 1) git remote add aosp ${REMOTE} else local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") @@ -274,15 +275,16 @@ function aospremote() function cloremote() { - if ! git rev-parse --git-dir &> /dev/null + local T=`git rev-parse --show-toplevel 2> /dev/null` + if [ -z "$T" ] then - echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." + echo "Git repository not found. Please run this from the directory of the Android repository you wish to set up." return 1 fi git remote rm clo 2> /dev/null - if [ -f ".gitupstream" ]; then - local REMOTE=$(cat .gitupstream | cut -d ' ' -f 1) + if [ -f "$T/.gitupstream" ]; then + local REMOTE=$(cat "$T/.gitupstream" | cut -d ' ' -f 1) git remote add clo ${REMOTE} else local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")