Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions scripts/sync_cute_subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ NO_TEMPORARY_WORKTREE=0
TEMP_WORKTREE_PATH=""
TEMP_WORKTREE_BRANCH=""
PREPARE_MERGE_COMMIT_MESSAGE="Rewrite vendored CuTe namespace to flash_attn.cute before subtree merge"
MERGE_COMMIT_MESSAGE="Merge upstream CuTe subtree updates"
REWRITE_COMMIT_MESSAGE="Rewrite vendored CuTe namespace to flash_sparse_attn.ops.cute"
MERGE_CONFLICT_OPTION="ours"
UPSTREAM_SPLIT_REF="HEAD"

usage() {
Expand Down Expand Up @@ -263,6 +265,34 @@ commit_prefix_if_changed() {
invoke_git -C "$repo" commit -m "$message"
}

cherry_pick_commit_back() {
local repo="$1"
local commit="$2"
local parent_count

parent_count="$(get_commit_parent_count "$repo" "$commit")"
if [[ "$parent_count" -gt 1 ]]; then
if invoke_git -C "$REPO_ROOT" cherry-pick -m 1 "$commit"; then
return 0
fi
else
if invoke_git -C "$REPO_ROOT" cherry-pick "$commit"; then
return 0
fi
fi

if git -C "$REPO_ROOT" rev-parse -q --verify CHERRY_PICK_HEAD >/dev/null 2>&1 \
&& git -C "$REPO_ROOT" diff --cached --quiet \
&& git -C "$REPO_ROOT" diff --quiet; then
echo "Cherry-pick $commit became empty after conflict resolution. Skipping ..."
invoke_git -C "$REPO_ROOT" cherry-pick --skip
return 0
fi

echo "Cherry-pick $commit failed with conflicts. Resolve manually and continue." >&2
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure message says "failed with conflicts", but git cherry-pick can also fail for non-conflict reasons (e.g., existing CHERRY_PICK_HEAD / other in-progress operations). Consider making this message more specific/guiding by including the next steps (e.g., git cherry-pick --continue / --abort) and/or suggesting git status to confirm the state.

Suggested change
echo "Cherry-pick $commit failed with conflicts. Resolve manually and continue." >&2
echo "Cherry-pick $commit failed. Run 'git -C \"$REPO_ROOT\" status' to inspect the repository state. If a cherry-pick is in progress, resolve it and run 'git -C \"$REPO_ROOT\" cherry-pick --continue', or run 'git -C \"$REPO_ROOT\" cherry-pick --abort' to cancel it." >&2

Copilot uses AI. Check for mistakes.
exit 1
}

invoke_core_sync() {
local work_repo_root="$1"
local cutlass_repo="$work_repo_root/csrc/cutlass"
Expand Down Expand Up @@ -322,7 +352,7 @@ invoke_core_sync() {

echo "Pulling upstream updates into $PREFIX ..."
invoke_git -C "$work_repo_root" fetch "$UPSTREAM_REPO_FOR_SPLIT" "$TEMP_BRANCH"
invoke_git_no_merge_edit -C "$work_repo_root" merge -X theirs "-Xsubtree=$PREFIX" FETCH_HEAD
invoke_git_no_merge_edit -C "$work_repo_root" merge -m "$MERGE_COMMIT_MESSAGE" "-X$MERGE_CONFLICT_OPTION" "-Xsubtree=$PREFIX" FETCH_HEAD
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MERGE_CONFLICT_OPTION defaults to ours, which changes conflict resolution from the previous -X theirs behavior. For a vendored subtree sync, preferring local changes on conflicts can silently drop upstream updates in conflicted hunks. Consider defaulting back to theirs (or making the strategy configurable via a CLI flag/env var) so upstream wins by default during the merge.

Suggested change
invoke_git_no_merge_edit -C "$work_repo_root" merge -m "$MERGE_COMMIT_MESSAGE" "-X$MERGE_CONFLICT_OPTION" "-Xsubtree=$PREFIX" FETCH_HEAD
invoke_git_no_merge_edit -C "$work_repo_root" merge -m "$MERGE_COMMIT_MESSAGE" "-X${MERGE_CONFLICT_OPTION:-theirs}" "-Xsubtree=$PREFIX" FETCH_HEAD

Copilot uses AI. Check for mistakes.
fi

echo "Rewriting vendored CuTe imports to flash_sparse_attn.ops.cute ..."
Expand Down Expand Up @@ -369,11 +399,7 @@ invoke_temporary_worktree_sync() {
[[ -z "$commit" ]] && continue
echo "Cherry-picking $commit back into current worktree ..."
ensure_git_identity "$REPO_ROOT"
if [[ "$(get_commit_parent_count "$temp_worktree" "$commit")" -gt 1 ]]; then
invoke_git -C "$REPO_ROOT" cherry-pick -m 1 "$commit"
else
invoke_git -C "$REPO_ROOT" cherry-pick "$commit"
fi
cherry_pick_commit_back "$temp_worktree" "$commit"
done <<< "$commits"

if [[ -n "$current_status" ]]; then
Expand Down
Loading