Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions docs/CLAUDE-WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ abstract-2nd → PR (base: abstract-1st, 前回からの差分のみ) → レビ
- **次のドラフト**: PR 作成後に自動的に次のブランチが作成される
- **PR の扱い**: PR はマージせず、レビュー完了後にクローズして次稿へ継続

### 教員の Suggest を次のドラフトに取り込む

PR 作成後、教員が Suggest を投稿した場合、それを次のドラフトブランチに取り込むことができます。

```bash
# 現在のブランチで自動判定して取り込み
git checkout 2nd-draft
./scripts/sync-suggestions.sh
# → 自動的に 1st-draft からの Suggest を取り込み

# ブランチを指定して実行
./scripts/sync-suggestions.sh 3rd-draft
# → 自動的に 2nd-draft からの Suggest を取り込み
```

**動作:**
- 現在のブランチ名から前のドラフトを自動判定
- 論文本体(xth-draft)と概要(abstract-xth)の両方に対応
- リモートから最新の変更を取得してマージ
- コンフリクトが発生した場合は手動で解決が必要

**注意事項:**
- `1st-draft` や `abstract-1st` では実行できません(前のドラフトが存在しないため)
- マージ後は `git push origin <ブランチ名>` でリモートに反映してください

## LaTeX コンパイル例

### 学部生論文のコンパイル
Expand Down
80 changes: 80 additions & 0 deletions scripts/sync-suggestions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

The script lacks execute permissions declaration. Add chmod +x instruction to the documentation or consider adding a check at the beginning of the script to ensure it has execute permissions.

Copilot uses AI. Check for mistakes.
# scripts/sync-suggestions.sh
#
# 前のドラフトブランチから教員の Suggest を取り込むスクリプト
#
# Usage:
# ./scripts/sync-suggestions.sh # 現在のブランチに対して自動判定
# ./scripts/sync-suggestions.sh 2nd-draft # 指定ブランチに対して実行

set -e

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

Consider using set -euo pipefail instead of just set -e. This will catch more errors: -u fails on undefined variables and -o pipefail fails if any command in a pipeline fails, not just the last one.

Suggested change
set -e
set -euo pipefail

Copilot uses AI. Check for mistakes.

# 引数があればそれを使用、なければ現在のブランチ
if [ -n "$1" ]; then
CURRENT_BRANCH="$1"

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

The git checkout on line 15 can fail if the branch doesn't exist locally or if there are uncommitted changes, but no error message is provided to explain what went wrong. Add validation and user-friendly error messages before attempting checkout.

Suggested change
CURRENT_BRANCH="$1"
CURRENT_BRANCH="$1"
# Check if branch exists locally
if ! git rev-parse --verify "$CURRENT_BRANCH" >/dev/null 2>&1; then
echo "Error: ブランチ '$CURRENT_BRANCH' はローカルに存在しません。"
exit 1
fi
# Check for uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "Error: 作業ディレクトリにコミットされていない変更があります。ブランチを切り替える前にコミットまたはスタッシュしてください。"
exit 1
fi

Copilot uses AI. Check for mistakes.
git checkout "$CURRENT_BRANCH"
else
CURRENT_BRANCH=$(git branch --show-current)
fi

echo "現在のブランチ: $CURRENT_BRANCH"

# 現在のブランチから前のドラフトを自動判定
if [[ "$CURRENT_BRANCH" =~ ^([0-9]+)(st|nd|rd|th)-draft$ ]]; then
# 論文本体 (例: 2nd-draft → 1st-draft)
CURRENT_NUM="${BASH_REMATCH[1]}"

if [ "$CURRENT_NUM" -eq 1 ]; then
# 1st-draft の場合は main から
PREV_BRANCH="main"
else
PREV_NUM=$((CURRENT_NUM - 1))
case $PREV_NUM in
1) SUFFIX="st" ;;
2) SUFFIX="nd" ;;
3) SUFFIX="rd" ;;
*) SUFFIX="th" ;;
esac
PREV_BRANCH="${PREV_NUM}${SUFFIX}-draft"
fi

elif [[ "$CURRENT_BRANCH" =~ ^abstract-([0-9]+)(st|nd|rd|th)$ ]]; then
# 概要 (例: abstract-2nd → abstract-1st)
CURRENT_NUM="${BASH_REMATCH[1]}"

if [ "$CURRENT_NUM" -eq 1 ]; then
echo "Error: abstract-1st には前のブランチがありません"
exit 1
else
PREV_NUM=$((CURRENT_NUM - 1))
case $PREV_NUM in
1) SUFFIX="st" ;;
2) SUFFIX="nd" ;;
3) SUFFIX="rd" ;;
*) SUFFIX="th" ;;
esac
PREV_BRANCH="abstract-${PREV_NUM}${SUFFIX}"
fi

else
echo "Error: draft または abstract ブランチではありません: $CURRENT_BRANCH"
exit 1
fi

echo "前のドラフト: $PREV_BRANCH"
echo ""

# リモートから最新を取得
echo "🔄 リモートから最新の変更を取得中..."
git fetch origin "$PREV_BRANCH"
git fetch origin "$CURRENT_BRANCH"
Comment on lines +69 to +70

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

If the remote branches don't exist, git fetch will fail but won't provide user-friendly error messages. Add error handling with clear messages like 'Branch $PREV_BRANCH not found on remote' to help users understand what went wrong.

Suggested change
git fetch origin "$PREV_BRANCH"
git fetch origin "$CURRENT_BRANCH"
if ! git fetch origin "$PREV_BRANCH"; then
echo "Error: Branch $PREV_BRANCH not found on remote (origin)"
exit 1
fi
if ! git fetch origin "$CURRENT_BRANCH"; then
echo "Error: Branch $CURRENT_BRANCH not found on remote (origin)"
exit 1
fi

Copilot uses AI. Check for mistakes.

# マージ実行
echo "🔀 $PREV_BRANCH からの変更を $CURRENT_BRANCH にマージ中..."
git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH"

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

The merge command will fail if there are merge conflicts, but users won't get guidance on how to resolve them. Consider wrapping this in a conditional that checks the exit status and provides instructions for conflict resolution (e.g., 'Conflicts detected. Please resolve them manually and run git merge --continue').

Suggested change
git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH"
if ! git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH"; then
echo ""
echo "⚠️ マージ中にコンフリクトが発生しました。"
echo "以下の手順でコンフリクトを解消してください:"
echo " 1. ファイルのコンフリクト箇所を手動で修正"
echo " 2. 修正後、'git add <修正したファイル>' を実行"
echo " 3. 'git merge --continue' または 'git commit' を実行"
echo ""
echo "解消後、再度 'git push origin $CURRENT_BRANCH' を実行してください。"
exit 1
fi

Copilot uses AI. Check for mistakes.

echo ""
echo "✅ 完了: $PREV_BRANCH からの Suggest を $CURRENT_BRANCH に取り込みました"
echo ""
echo "次のステップ:"
echo " git push origin $CURRENT_BRANCH"