Skip to content

Commit 1078e82

Browse files
committed
refactor: extract function for remote
1 parent 604b087 commit 1078e82

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

.devcontainer/setup.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,39 @@ GREEN="\033[0;32m"
55
YELLOW="\033[1;33m"
66
NC="\033[0m" # no color
77

8+
set_or_add_remote() {
9+
local REMOTE_NAME=$1
10+
local REMOTE_URL=$2
11+
local REPO_PATH="/workspaces/$REPO_NAME"
12+
13+
git -C "$REPO_PATH" remote get-url "$REMOTE_NAME" &>/dev/null || git -C "$REPO_PATH" remote add "$REMOTE_NAME" "$REMOTE_URL"
14+
git -C "$REPO_PATH" remote set-url "$REMOTE_NAME" "$REMOTE_URL"
15+
}
16+
817
setup_repo() {
918
local DIR_NAME="$1"
1019
local DIR_PATH="/workspaces/$DIR_NAME"
1120
local REPO="Azure/$DIR_NAME"
1221

1322
if [ -d "$DIR_PATH" ]; then
1423
echo -e "\n${YELLOW}($DIR_NAME) Pulling the latest changes from upstream...${NC}"
24+
gh repo fork "$REPO" --clone=false
1525
else
1626
echo -e "\n${GREEN}($DIR_NAME) Forking and cloning the repository...${NC}"
1727
gh repo fork "$REPO" --clone=true
1828
fi
1929

20-
HEAD_BRANCH=$(git -C "$DIR_PATH" remote show upstream | grep "HEAD branch" | awk '{print $NF}')
21-
git -C "$DIR_PATH" pull -r upstream "$HEAD_BRANCH"
30+
cd "$DIR_PATH"
31+
gh repo sync --source "$REPO"
32+
cd /workspaces
2233
}
2334

2435
SECONDS=0
2536

37+
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
38+
set_or_add_remote origin "https://github.com/$GITHUB_USER/$REPO_NAME.git"
39+
set_or_add_remote upstream "https://github.com/Azure/$REPO_NAME.git"
40+
2641
pip install aaz-dev
2742

2843
# azdev repositories

0 commit comments

Comments
 (0)