From d97a0e1484724c930f357498684b700a25536475 Mon Sep 17 00:00:00 2001 From: gavrielc Date: Thu, 23 Apr 2026 00:21:15 +0300 Subject: [PATCH] fix(setup): resolve channels remote dynamically, don't assume `origin` Forks that keep the upstream nanoclaw repo under a non-origin remote name (typically `upstream`, with `origin` pointing at the user's fork) hit "git fetch origin channels failed" when adding a channel, because the fork doesn't carry the channels branch. New setup/lib/channels-remote.sh walks `git remote -v` for a url matching qwibitai/nanoclaw, auto-adds `upstream` if none matches, and honors NANOCLAW_CHANNELS_REMOTE as an override. Wired into the four add-*.sh scripts that setup:auto invokes (discord, telegram, whatsapp, teams). Co-Authored-By: Claude Opus 4.7 (1M context) --- setup/add-discord.sh | 12 +++++++++--- setup/add-teams.sh | 12 +++++++++--- setup/add-telegram.sh | 12 +++++++++--- setup/add-whatsapp.sh | 12 +++++++++--- setup/lib/channels-remote.sh | 38 ++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 setup/lib/channels-remote.sh diff --git a/setup/add-discord.sh b/setup/add-discord.sh index 1cd247a..74ce9a7 100755 --- a/setup/add-discord.sh +++ b/setup/add-discord.sh @@ -16,7 +16,13 @@ cd "$PROJECT_ROOT" # Keep in sync with .claude/skills/add-discord/SKILL.md. ADAPTER_VERSION="@chat-adapter/discord@4.26.0" -CHANNELS_BRANCH="origin/channels" + +# Resolve which remote carries the channels branch — handles forks where +# upstream lives on a different remote than `origin`. +# shellcheck source=setup/lib/channels-remote.sh +source "$PROJECT_ROOT/setup/lib/channels-remote.sh" +CHANNELS_REMOTE=$(resolve_channels_remote) +CHANNELS_BRANCH="${CHANNELS_REMOTE}/channels" emit_status() { local status=$1 error=${2:-} @@ -54,8 +60,8 @@ ADAPTER_ALREADY_INSTALLED=true if need_install; then ADAPTER_ALREADY_INSTALLED=false log "Fetching channels branch…" - git fetch origin channels >&2 2>/dev/null || { - emit_status failed "git fetch origin channels failed" + git fetch "$CHANNELS_REMOTE" channels >&2 2>/dev/null || { + emit_status failed "git fetch ${CHANNELS_REMOTE} channels failed" exit 1 } diff --git a/setup/add-teams.sh b/setup/add-teams.sh index f116f24..99ceb4a 100755 --- a/setup/add-teams.sh +++ b/setup/add-teams.sh @@ -19,7 +19,13 @@ cd "$PROJECT_ROOT" # Keep in sync with .claude/skills/add-teams/SKILL.md. ADAPTER_VERSION="@chat-adapter/teams@4.26.0" -CHANNELS_BRANCH="origin/channels" + +# Resolve which remote carries the channels branch — handles forks where +# upstream lives on a different remote than `origin`. +# shellcheck source=setup/lib/channels-remote.sh +source "$PROJECT_ROOT/setup/lib/channels-remote.sh" +CHANNELS_REMOTE=$(resolve_channels_remote) +CHANNELS_BRANCH="${CHANNELS_REMOTE}/channels" emit_status() { local status=$1 error=${2:-} @@ -61,8 +67,8 @@ ADAPTER_ALREADY_INSTALLED=true if need_install; then ADAPTER_ALREADY_INSTALLED=false log "Fetching channels branch…" - git fetch origin channels >&2 2>/dev/null || { - emit_status failed "git fetch origin channels failed" + git fetch "$CHANNELS_REMOTE" channels >&2 2>/dev/null || { + emit_status failed "git fetch ${CHANNELS_REMOTE} channels failed" exit 1 } diff --git a/setup/add-telegram.sh b/setup/add-telegram.sh index 361960f..0d7fd5c 100755 --- a/setup/add-telegram.sh +++ b/setup/add-telegram.sh @@ -16,7 +16,13 @@ cd "$PROJECT_ROOT" # Keep in sync with .claude/skills/add-telegram/SKILL.md. ADAPTER_VERSION="@chat-adapter/telegram@4.26.0" -CHANNELS_BRANCH="origin/channels" + +# Resolve which remote carries the channels branch — handles forks where +# upstream lives on a different remote than `origin`. +# shellcheck source=setup/lib/channels-remote.sh +source "$PROJECT_ROOT/setup/lib/channels-remote.sh" +CHANNELS_REMOTE=$(resolve_channels_remote) +CHANNELS_BRANCH="${CHANNELS_REMOTE}/channels" emit_status() { local status=$1 error=${2:-} @@ -53,8 +59,8 @@ ADAPTER_ALREADY_INSTALLED=true if need_install; then ADAPTER_ALREADY_INSTALLED=false log "Fetching channels branch…" - git fetch origin channels >&2 2>/dev/null || { - emit_status failed "git fetch origin channels failed" + git fetch "$CHANNELS_REMOTE" channels >&2 2>/dev/null || { + emit_status failed "git fetch ${CHANNELS_REMOTE} channels failed" exit 1 } diff --git a/setup/add-whatsapp.sh b/setup/add-whatsapp.sh index d04d372..c7356af 100755 --- a/setup/add-whatsapp.sh +++ b/setup/add-whatsapp.sh @@ -20,7 +20,13 @@ BAILEYS_VERSION="@whiskeysockets/baileys@6.17.16" QRCODE_VERSION="qrcode@1.5.4" QRCODE_TYPES_VERSION="@types/qrcode@1.5.6" PINO_VERSION="pino@9.6.0" -CHANNELS_BRANCH="origin/channels" + +# Resolve which remote carries the channels branch — handles forks where +# upstream lives on a different remote than `origin`. +# shellcheck source=setup/lib/channels-remote.sh +source "$PROJECT_ROOT/setup/lib/channels-remote.sh" +CHANNELS_REMOTE=$(resolve_channels_remote) +CHANNELS_BRANCH="${CHANNELS_REMOTE}/channels" emit_status() { local status=$1 error=${2:-} @@ -47,8 +53,8 @@ ADAPTER_ALREADY_INSTALLED=true if need_install; then ADAPTER_ALREADY_INSTALLED=false log "Fetching channels branch…" - git fetch origin channels >&2 2>/dev/null || { - emit_status failed "git fetch origin channels failed" + git fetch "$CHANNELS_REMOTE" channels >&2 2>/dev/null || { + emit_status failed "git fetch ${CHANNELS_REMOTE} channels failed" exit 1 } diff --git a/setup/lib/channels-remote.sh b/setup/lib/channels-remote.sh new file mode 100644 index 0000000..6da0159 --- /dev/null +++ b/setup/lib/channels-remote.sh @@ -0,0 +1,38 @@ +# channels-remote.sh — resolve the git remote that carries the `channels` +# branch. Source this file and call `resolve_channels_remote`; echoes the +# remote name (e.g. `origin` or `upstream`). +# +# Typical fork setups keep the upstream nanoclaw repo under a remote named +# `upstream`, with `origin` pointing at the user's fork. The channels branch +# only lives upstream, so a hardcoded `git fetch origin channels` fails for +# forks. This helper walks `git remote -v`, picks the remote whose URL points +# at qwibitai/nanoclaw, and prints its name. +# +# Fallback: if no existing remote matches, add `upstream` pointing at +# github.com/qwibitai/nanoclaw and return that — keeps forks without an +# explicit upstream configured working on the first try. +# +# Explicit override: set NANOCLAW_CHANNELS_REMOTE= to skip detection. + +resolve_channels_remote() { + if [ -n "${NANOCLAW_CHANNELS_REMOTE:-}" ]; then + printf '%s' "$NANOCLAW_CHANNELS_REMOTE" + return 0 + fi + + local remote url + while IFS=$'\t' read -r remote url; do + case "$url" in + *qwibitai/nanoclaw*) + printf '%s' "$remote" + return 0 + ;; + esac + done < <(git remote -v 2>/dev/null | awk '$3 == "(fetch)" { print $1"\t"$2 }') + + # No matching remote — add `upstream` and use it. Silent on failure so + # callers see the eventual `git fetch` error rather than a cryptic + # remote-add failure. + git remote add upstream https://github.com/qwibitai/nanoclaw.git 2>/dev/null || true + printf '%s' "upstream" +}