Commit 6bc8d6d3 authored by Lei Wang's avatar Lei Wang Committed by LeiWang1999
Browse files

[Enhancement] Update format script to support upstream repository for file formatting (#221)

- Modified `format.sh` to first check for the upstream repository before falling back to the local `origin/main` branch for determining the merge base.
- Improved logic to handle cases where the upstream repository is not available, ensuring robust file formatting across branches.
parent 01526645
......@@ -65,19 +65,25 @@ format_changed() {
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only format files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
UPSTREAM_REPO="https://github.com/tile-ai/tilelang"
if git ls-remote --exit-code "$UPSTREAM_REPO" main &>/dev/null; then
# First try to use the upstream repository directly
MERGEBASE="$(git fetch "$UPSTREAM_REPO" main &>/dev/null && git merge-base FETCH_HEAD HEAD)"
elif git show-ref --verify --quiet refs/remotes/origin/main; then
# Fall back to origin/main if available
BASE_BRANCH="origin/main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
else
# Last resort, use local main
BASE_BRANCH="main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
fi
}
# Format all files
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment