Skip to content

Commit

Permalink
add test for shell subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou-schrodinger committed Jan 18, 2021
1 parent a96d4a7 commit f4d56d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ To see the pre-defined sub-commands, run `gita -h` or take a look at
[cmds.yml](https://github.com/nosarthur/gita/blob/master/gita/cmds.yml).
To add your own sub-commands, see the [customization section](#custom).
To run arbitrary `git` command, see the [superman mode section](#superman).
To run arbitrary shell command, see the [shell mode section](#shell).

The branch color distinguishes 5 situations between local and remote branches:

Expand Down Expand Up @@ -157,6 +158,21 @@ For example,
- `gita super frontend-repo backend-repo commit -am 'implement a new feature'`
executes `git commit -am 'implement a new feature'` for `frontend-repo` and `backend-repo`

## <a name='shell'></a> Shell mode

The shell mode delegates any shell command.
Usage:

```
gita shell [repo-name(s) or group-name(s)] <any-shell-command>
```

Here `repo-name(s)` or `group-name(s)` are optional, and their absence means all repos.
For example,

- `gita shell ll` lists contents for all repos
- `gita shell repo1 mkdir docs` create a new directory `docs` in repo1

## <a name='custom'></a> Customization

### user-defined sub-command using yaml file
Expand Down Expand Up @@ -195,6 +211,12 @@ comaster:
help: checkout the master branch
```

### customize the local/remote relationship coloring displayed by the `gita ll` command

You can see the default color scheme and the available colors via `gita color`.
To change the color coding, use `gita color set <situation> <color>`.
The configuration is saved in `$XDG_CONFIG_HOME/gita/color.yml`.

### customize information displayed by the `gita ll` command

You can customize the information displayed by `gita ll`.
Expand All @@ -208,12 +230,6 @@ For example, the default information items setting corresponds to
- commit_msg
```

### customize the local/remote relationship coloring displayed by the `gita ll` command

You can see the default color scheme and the available colors via `gita color`.
To change the color coding, use `gita color set <situation> <color>`.
The configuration is saved in `$XDG_CONFIG_HOME/gita/color.yml`.

## Requirements

Gita requires Python 3.6 or higher, due to the use of
Expand Down
14 changes: 14 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ def test_superman(mock_run, _, input):
mock_run.assert_called_once_with(expected_cmds, cwd='path7')


@pytest.mark.parametrize('input', [
'diff --name-only --staged',
"commit -am 'lala kaka'",
])
@patch('gita.utils.get_repos', return_value={'repo7': 'path7'})
@patch('subprocess.run')
def test_shell(mock_run, _, input):
mock_run.reset_mock()
args = ['shell', 'repo7'] + shlex.split(input)
__main__.main(args)
expected_cmds = shlex.split(input)
mock_run.assert_called_once_with(expected_cmds, cwd='path7', check=True, stderr=-2, stdout=-1)


class TestContext:

@patch('gita.utils.get_context', return_value=None)
Expand Down

0 comments on commit f4d56d5

Please sign in to comment.