# mock-git **Repository Path**: mirrors_stevemao/mock-git ## Basic Information - **Project Name**: mock-git - **Description**: Mock any git command - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2025-09-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mock-git [![Build Status: Linux](https://travis-ci.org/stevemao/mock-git.svg?branch=master)](https://travis-ci.org/stevemao/mock-git) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/76bg3fbqo2ox9s11/branch/master?svg=true)](https://ci.appveyor.com/project/stevemao/mock-git/branch/master) > Mock any git command Useful for mocking tests that run git command, especially to fake edge cases and increase test coverage. ## Install ``` $ npm install --save-dev mock-git ``` ## Usage ```js const mockGit = require('mock-git'); const log = 'mocking git bla!'; const unmock = await mockGit(`console.log('${log}')`, 'bla'); let actual = shell.exec('git bla').stdout; t.is(log + '\n', actual); actual = shell.exec('git').stdout; t.not(log + '\n', actual); unmock(); actual = shell.exec('git bla').stdout; t.not(log + '\n', actual); ``` Checkout the [tests](./test.js) for more details ## API ### mockGit(js, [command]) Returns a promise which resolves with an unmock function. ##### js Type: `string` Nodejs code. #### command Type: `string` EG: `'commit'`. If omitted, it will mock the git binary. ## Related - [mock-bin](https://github.com/stevemao/mock-bin) - Mock any executable binary ## License MIT © [Steve Mao](https://github.com/stevemao)