> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xenoci.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test before every push

> box setup --pre-push adds a git hook to one repository, so every git push runs box test first and stops when the tests fail

> [!NOTE]
>
> **When to use it.**
>
> * You want a broken push to stop on your machine, before it starts a CI run
> * Your agent pushes on its own and you want its tests checked every time

## Turn it on

From the root of the git repository

```bash theme={"system"}
box setup --pre-push
```

<video controls muted loop playsInline autoPlay preload="metadata" poster="/media/docs/ios-pre-push-poster.webp" src="https://mintcdn.com/xenoci/ZFKGlbE4Q2bw14Om/media/docs/ios-pre-push.mp4?fit=max&auto=format&n=ZFKGlbE4Q2bw14Om&q=85&s=a8dd0111340c96094ff6974a15cccd39" width="1280" height="778" />

box setup --pre-push, then a git push stopped because a test fails

```text theme={"system"}
box: installed ./.git/hooks/pre-push
box: every git push from this repository now runs `box test` first and stops when the tests fail; skip once: git push --no-verify; turn off: box setup --pre-push --off
```

## What a push looks like

```text theme={"system"}
box: pre-push: running box test before the push (skip once: git push --no-verify)
box: queue: job bj_n7nWHXFKLvrVHlyS (test, ios, $0.05/min) submitted
box: status: running
box: build: xcodebuild build-for-testing
box: build: done in 9s
box: test: running the tests on the simulator
box: status: succeeded
box: tests 1 passed, 0 failed
box: bj_n7nWHXFKLvrVHlyS succeeded, 60s billed, $0.05
 * [new branch]      HEAD -> main
```

> [!NOTE]
>
> Job `bj_n7nWHXFKLvrVHlyS` on the production Mac: 60 s billed, \$0.05

With a failing test the push stops after the `FAIL` lines shown on the [Test](https://docs.xenoci.com/ios/test.md) page, with this line, and nothing reaches the remote

```text theme={"system"}
box: pre-push: the tests failed, so the push was stopped. Fix them and push again, or push anyway with: git push --no-verify
```

## How it behaves

* Failing tests stop the push (exit 1). Fix them and push again
* `git push --no-verify` skips the hook once
* A push that only deletes branches runs nothing
* The hook lives in this repository’s `.git/hooks` only, never in your git config. A pre-push hook that is not box’s is left alone; with husky or lefthook, add `box test` to their pre-push hook instead

```bash theme={"system"}
box setup --pre-push --off  # remove the hook
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.