You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cycode’s pre-commit hook can be set up within your local repository so that the Cycode CLI application will identify any issues with your code automatically before you commit it to your codebase.
217
+
Cycode's pre-commit and pre-push hooks can be set up within your local repository so that the Cycode CLI application will identify any issues with your code automatically before you commit or push it to your codebase.
217
218
218
219
> [!NOTE]
219
-
> pre-commit hook is not available for IaC scans.
220
+
> pre-commit and pre-push hooks are not available for IaC scans.
220
221
221
222
Perform the following steps to install the pre-commit hook:
222
223
224
+
### Installing Pre-Commit Hook
225
+
223
226
1. Install the pre-commit framework (Python 3.9 or higher must be installed):
224
227
225
228
```bash
@@ -233,29 +236,25 @@ Perform the following steps to install the pre-commit hook:
233
236
```yaml
234
237
repos:
235
238
- repo: https://github.com/cycodehq/cycode-cli
236
-
rev: v3.4.2
239
+
rev: v3.5.0
237
240
hooks:
238
241
- id: cycode
239
-
stages:
240
-
- pre-commit
242
+
stages: [pre-commit]
241
243
```
242
244
243
245
4. Modify the created file for your specific needs. Use hook ID `cycode` to enable scan for Secrets. Use hook ID `cycode-sca` to enable SCA scan. Use hook ID `cycode-sast` to enable SAST scan. If you want to enable all scanning types, use this configuration:
244
246
245
247
```yaml
246
248
repos:
247
249
- repo: https://github.com/cycodehq/cycode-cli
248
-
rev: v3.4.2
250
+
rev: v3.5.0
249
251
hooks:
250
252
- id: cycode
251
-
stages:
252
-
- pre-commit
253
+
stages: [pre-commit]
253
254
- id: cycode-sca
254
-
stages:
255
-
- pre-commit
255
+
stages: [pre-commit]
256
256
- id: cycode-sast
257
-
stages:
258
-
- pre-commit
257
+
stages: [pre-commit]
259
258
```
260
259
261
260
5. Install Cycode’s hook:
@@ -278,6 +277,37 @@ Perform the following steps to install the pre-commit hook:
278
277
> Trigger happens on `git commit` command.
279
278
> Hook triggers only on the files that are staged for commit.
280
279
280
+
### Installing Pre-Push Hook
281
+
282
+
To install the pre-push hook in addition to or instead of the pre-commit hook:
283
+
284
+
1. Add the pre-push hooks to your `.pre-commit-config.yaml` file:
285
+
286
+
```yaml
287
+
repos:
288
+
- repo: https://github.com/cycodehq/cycode-cli
289
+
rev: v3.5.0
290
+
hooks:
291
+
- id: cycode-pre-push
292
+
stages: [pre-push]
293
+
```
294
+
295
+
2. Install the pre-push hook:
296
+
297
+
```bash
298
+
pre-commit install --hook-type pre-push
299
+
```
300
+
301
+
3. For both pre-commit and pre-push hooks, use:
302
+
303
+
```bash
304
+
pre-commit install
305
+
pre-commit install --hook-type pre-push
306
+
```
307
+
308
+
> [!NOTE]
309
+
> Pre-push hooks trigger on `git push` command and scan only the commits about to be pushed.
310
+
281
311
# Cycode CLI Commands
282
312
283
313
The following are the options and commands available with the Cycode CLI application:
@@ -786,6 +816,107 @@ After installing the pre-commit hook, you may occasionally wish to skip scanning
786
816
SKIP=cycode git commit -m <your commit message>`
787
817
```
788
818
819
+
### Pre-Push Scan
820
+
821
+
A pre-push scan automatically identifies any issues before you push changes to the remote repository. This hook runs on the client side and scans only the commits that are about to be pushed, making it efficient for catching issues before they reach the remote repository.
822
+
823
+
> [!NOTE]
824
+
> Pre-push hook is not available for IaC scans.
825
+
826
+
The pre-push hook integrates with the pre-commit framework and can be configured to run before any `git push` operation.
827
+
828
+
#### Installing Pre-Push Hook
829
+
830
+
To set up the pre-push hook using the pre-commit framework:
831
+
832
+
1. Install the pre-commit framework (if not already installed):
833
+
834
+
```bash
835
+
pip3 install pre-commit
836
+
```
837
+
838
+
2. Create or update your `.pre-commit-config.yaml` file to include the pre-push hooks:
839
+
840
+
```yaml
841
+
repos:
842
+
- repo: https://github.com/cycodehq/cycode-cli
843
+
rev: v3.5.0
844
+
hooks:
845
+
- id: cycode-pre-push
846
+
stages: [pre-push]
847
+
```
848
+
849
+
3. For multiple scan types, use this configuration:
850
+
851
+
```yaml
852
+
repos:
853
+
- repo: https://github.com/cycodehq/cycode-cli
854
+
rev: v3.5.0
855
+
hooks:
856
+
- id: cycode-pre-push # Secrets scan
857
+
stages: [pre-push]
858
+
- id: cycode-sca-pre-push # SCA scan
859
+
stages: [pre-push]
860
+
- id: cycode-sast-pre-push # SAST scan
861
+
stages: [pre-push]
862
+
```
863
+
864
+
4. Install the pre-push hook:
865
+
866
+
```bash
867
+
pre-commit install --hook-type pre-push
868
+
```
869
+
870
+
A successful installation will result in the message: `Pre-push installed at .git/hooks/pre-push`.
871
+
872
+
5. Keep the pre-push hook up to date:
873
+
874
+
```bash
875
+
pre-commit autoupdate
876
+
```
877
+
878
+
#### How Pre-Push Scanning Works
879
+
880
+
The pre-push hook:
881
+
- Receives information about what commits are being pushed
882
+
- Calculates the appropriate commit range to scan
883
+
- For new branches: scans all commits from the merge base with the default branch
884
+
- For existing branches: scans only the new commits since the last push
885
+
- Runs the same comprehensive scanning as other Cycode scan modes
886
+
887
+
#### Smart Default Branch Detection
888
+
889
+
The pre-push hook intelligently detects the default branch for merge base calculation using this priority order:
This smart detection ensures the pre-push hook works correctly regardless of whether your repository uses `main`, `master`, `develop`, or any other default branch name.
902
+
903
+
#### Skipping Pre-Push Scans
904
+
905
+
To skip the pre-push scan for a specific push operation, use:
906
+
907
+
```bash
908
+
SKIP=cycode-pre-push git push
909
+
```
910
+
911
+
Or to skip all pre-push hooks:
912
+
913
+
```bash
914
+
git push --no-verify
915
+
```
916
+
917
+
> [!TIP]
918
+
> The pre-push hook is triggered on `git push` command and scans only the commits that are about to be pushed, making it more efficient than scanning the entire repository.
919
+
789
920
## Scan Results
790
921
791
922
Each scan will complete with a message stating if any issues were found or not.
0 commit comments