@@ -18,46 +18,39 @@ if ! command -v aaz-dev &> /dev/null; then
1818 NC=" \033[0m" # no color
1919
2020 set_or_add_remote () {
21- local REMOTE_NAME=$1
22- local REMOTE_URL=$2
23- local REPO_PATH=" /workspaces/$REPO_NAME "
24-
25- git -C " $REPO_PATH " remote get-url " $REMOTE_NAME " & > /dev/null || git -C " $REPO_PATH " remote add " $REMOTE_NAME " " $REMOTE_URL "
26- git -C " $REPO_PATH " remote set-url " $REMOTE_NAME " " $REMOTE_URL "
21+ local REPO=$1
22+ local REMOTE=$2
23+ local DIR=" /workspaces/$REPO "
24+ local OWNER=$( [ " $REMOTE " = " origin" ] && echo " $GITHUB_USER " || echo " Azure" )
25+ local URL=" https://github.com/$OWNER /$REPO .git"
26+
27+ git -C " $DIR " remote get-url " $REMOTE " & > /dev/null || git -C " $DIR " remote add " $REMOTE " " $URL "
28+ git -C " $DIR " remote set-url " $REMOTE " " $URL "
2729 }
2830
2931 setup_repo () {
30- local DIR_NAME=" $1 "
31- local DIR_PATH=" /workspaces/$DIR_NAME "
32- local REPO=" Azure/$DIR_NAME "
32+ local REPO=$1
33+ local DIR=" /workspaces/$REPO "
3334
34- if [ -d " $DIR_PATH " ]; then
35- echo -e " \n${YELLOW} ($DIR_NAME ) Pulling the latest changes from upstream...${NC} "
36- gh repo fork " $REPO " --clone=false
37- else
38- echo -e " \n${GREEN} ($DIR_NAME ) Forking and cloning the repository...${NC} "
39- gh repo fork " $REPO " --clone -- --depth=1
40- fi
35+ echo
36+ gh repo fork " Azure/$REPO " --clone=false --default-branch-only
4137
42- # `git` doesn't work well with private repository
43- if [ " $( gh repo view " $REPO " --json visibility --jq ' .visibility' ) " == " PRIVATE" ]; then
44- cd " $DIR_PATH "
45- gh repo sync --source " $REPO "
46- cd /workspaces
38+ if [ -d " $DIR " ]; then
39+ set_or_add_remote " $REPO " origin
40+ set_or_add_remote " $REPO " upstream
4741 else
48- DEFAULT_BRANCH=$( git -C " $DIR_PATH " remote show upstream | grep " HEAD branch" | awk ' {print $NF}' )
49- git -C " $DIR_PATH " pull -r upstream " $DEFAULT_BRANCH "
42+ git clone " https://github.com/$GITHUB_USER /$REPO .git" --single-branch --no-tags
43+ set_or_add_remote " $REPO " upstream
44+
45+ # Synchronize with upstream
46+ BRANCH=$( git -C " $DIR " remote show upstream | grep " HEAD branch" | awk ' {print $NF}' )
47+ git -C " $DIR " pull -r upstream " $BRANCH "
5048 fi
5149 }
5250
53- echo -e " \n${GREEN} Welcome to the dev environment setup wizard.${NC} \n"
54-
5551 SECONDS=0
5652
57- REPO_NAME=$( basename " $GITHUB_REPOSITORY " )
58- set_or_add_remote origin " https://github.com/$GITHUB_USER /$REPO_NAME .git"
59- set_or_add_remote upstream " https://github.com/Azure/$REPO_NAME .git"
60-
53+ echo
6154 uv pip install aaz-dev
6255
6356 # `azdev` repositories
@@ -69,10 +62,13 @@ if ! command -v aaz-dev &> /dev/null; then
6962 # `aaz-dev` repositories
7063 setup_repo " aaz"
7164 setup_repo " azure-rest-api-specs"
72- setup_repo " azure-rest-api-specs-pr"
7365
7466 ELAPSED_TIME=$SECONDS
67+
7568 echo -e " \n${YELLOW} Elapsed time: $(( ELAPSED_TIME / 60 )) m $(( ELAPSED_TIME % 60 )) s.${NC} "
7669 echo -e " \n${GREEN} Finished setup! Please launch the codegen tool via:${NC} "
77- echo -e " ${GREEN} aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz${NC} \n"
70+ echo -e " ${GREEN} \$ aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz${NC} \n"
71+ else
72+ echo -e " \n${GREEN} Please launch the codegen tool via:${NC} "
73+ echo -e " ${GREEN} \$ aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz${NC} \n"
7874fi
0 commit comments