---
description: "Port a commit from another project into pharmacy-starter on its own branch and push to Bitbucket"
allowed_tools: ["Read", "Edit", "Write", "Bash", "Glob", "Grep"]
---

# Port Commit from External Project

Port a single commit from another local project into pharmacy-starter, creating a correctly-named branch and pushing to Bitbucket.

## Usage
```
/mtc-get-commit <path-to-project> <commit-hash>
```

### Examples
```
/mtc-get-commit /Users/kieranmcburney/Projects/Dr-Nicole/public_mcb 31a9ca7
/mtc-get-commit ~/Projects/SomeClient/public_mcb abc1234
```

## Arguments

- `$ARGUMENTS` — Two space-separated values: the absolute path to the source project directory, and the git commit hash to port.

## Process

### Step 1: Parse Arguments

Split `$ARGUMENTS` into two parts:
- **Source project path** — the first argument (absolute path to the source project's git root)
- **Commit hash** — the second argument (short or full git hash)

If either argument is missing, stop and ask the user.

### Step 2: Read the Commit from the Source Project

Run these commands against the **source project directory** (not pharmacy-starter):

```bash
cd <source-path> && git log <hash> -1 --format="%s%n%n%b"
cd <source-path> && git show <hash> --stat
cd <source-path> && git diff <hash>^..<hash>
```

This gives you the commit message, file list, and full diff. Study the diff carefully before proceeding.

### Step 3: Determine Branch Name

Analyse the commit message and choose the correct branch prefix based on the project's semantic branching model:

| Branch Type     | When to Use                | Example                          |
|-----------------|----------------------------|----------------------------------|
| `feature/*`     | New feature development    | `feature/user-login-ui`          |
| `bugfix/*`      | Bug or issue fix           | `bugfix/order-total-rounding`    |
| `improvement/*` | General enhancement        | `improvement/refactor-auth`      |
| `hotfix/*`      | Critical production fix    | `hotfix/crash-on-checkout`       |

Generate a descriptive kebab-case suffix from the commit message. **Present the proposed branch name to the user and wait for confirmation before proceeding.**

### Step 4: Stash and Create Branch

1. Note the current branch name (you'll return to it later):
   ```bash
   git branch --show-current
   ```
2. If there are uncommitted changes, stash them:
   ```bash
   git stash
   ```
3. Fetch latest master and create the new branch:
   ```bash
   git fetch origin master
   git checkout -b <branch-name> origin/master
   ```

### Step 5: Apply Changes

Process each file from the diff. For every file:

- **Modified files**: Read the corresponding file in pharmacy-starter first, then apply edits using the Edit tool. For large files, read only the relevant sections.
- **New files**: Create the file using the Write tool. Ensure parent directories exist first.
- **Deleted files**: Remove using `rm` via Bash.

Work through files methodically. Do not skip any files from the diff.

### Step 6: Commit

Stage all changed files **individually by name** (never use `git add .` or `git add -A`):

```bash
git add path/to/file1 path/to/file2 ...
```

Commit with the **exact original commit message** from the source project:

```bash
git commit -m "$(cat <<'EOF'
<original subject line>

<original body, if any>
EOF
)"
```

### Step 7: Push to Bitbucket

```bash
git push -u origin <branch-name>
```

### Step 8: Restore Previous State

Switch back to the original branch and restore any stashed changes:

```bash
git checkout <original-branch>
git stash pop  # only if you stashed in Step 4
```

### Step 9: Report

Output a summary:
- Branch name and Bitbucket URL
- Number of files changed
- The original commit message
- Confirmation that the working tree is back to its original state

## Rules

- **Always branch off latest `origin/master`** — fetch before creating the branch
- **Stage files individually** — never `git add .` or `git add -A`
- **Preserve the original commit message exactly** — do not modify, summarise, or append to it
- **No Co-Authored-By lines** — do not add any co-author attribution
- **No AI/Claude references** — do not mention AI in commit messages
- **Skip local dev files** — do not include `.htaccess`, `includes.less`, `main-app.js`, or other local configuration files in the commit, even if they appear in the source diff
- **Read before editing** — always read the target file in pharmacy-starter before applying edits
- **Never force-push** — if a push fails, stop and ask the user
- **One commit per branch** — each invocation ports exactly one commit onto one new branch

ARGUMENTS: $ARGUMENTS
