Skip to content

Commit

Permalink
Merge branch 'quiet'
Browse files Browse the repository at this point in the history
* quiet:
  Add quiet option
  Add quiet support
  Fix imports

Fixes #30
  • Loading branch information
Brickster committed Dec 21, 2015
2 parents 2fd194f + 8952d3c commit 51cd6fa
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 53 deletions.
10 changes: 5 additions & 5 deletions bin/commands/abandon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
from subprocess import call, check_output

from commands.utils import directories
from commands.utils.messages import error
from utils import directories
from utils.messages import error, info


def abandon(start, end, dry_run=False):
def abandon(start, end, dry_run=False, quiet=False):
"""Drop a range of stashes from start (inclusive) to end (exclusive)."""

if not directories.is_git_repository():
Expand All @@ -26,10 +26,10 @@ def abandon(start, end, dry_run=False):
for i in range(start, end):
stash = 'stash@{{{}}}'.format(i)
stash_sha = check_output(['git', 'rev-parse', stash]).splitlines()[0]
print 'Would drop refs/{} ({})'.format(stash, stash_sha)
info('Would drop refs/{} ({})'.format(stash, stash_sha))
else:
start_stash = 'stash@{{{}}}'.format(start)
for i in range(start, end):
stash_sha = check_output(['git', 'rev-parse', start_stash]).splitlines()[0]
call(['git', 'stash', 'drop', '--quiet', start_stash])
print 'Dropped refs/stash@{{{}}} ({})'.format(i, stash_sha)
info('Dropped refs/stash@{{{}}} ({})'.format(i, stash_sha), quiet)
4 changes: 2 additions & 2 deletions bin/commands/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys
from subprocess import call, check_output

from commands.utils import directories
from commands.utils.messages import error, info
from utils import directories
from utils.messages import error, info


def changes(branch, details=None, color_when='auto'):
Expand Down
8 changes: 4 additions & 4 deletions bin/commands/restash.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
from subprocess import check_output, PIPE, Popen

from commands.utils import directories
from commands.utils.messages import error
from utils import directories
from utils.messages import error, info


def _is_valid_stash(stash):
Expand All @@ -21,7 +21,7 @@ def _is_valid_stash(stash):
return proc.returncode == 0


def restash(stash='stash@{0}'):
def restash(stash='stash@{0}', quiet=False):
"""Restash a stash reference."""

if not directories.is_git_repository():
Expand All @@ -37,6 +37,6 @@ def restash(stash='stash@{0}'):

if not restash_proc.returncode:
stash_sha = check_output(['git', 'rev-parse', stash]).splitlines()[0]
print 'Restashed {} ({})'.format(stash, stash_sha)
info('Restashed {} ({})'.format(stash, stash_sha), quiet)
else:
sys.exit(1)
4 changes: 2 additions & 2 deletions bin/commands/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import re
from subprocess import call, check_output, PIPE, Popen, STDOUT

from commands.utils import directories
from commands.utils.messages import error
from utils import directories
from utils.messages import error


def list(section, config, count, keys, format, file=None):
Expand Down
8 changes: 4 additions & 4 deletions bin/commands/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
from subprocess import call, check_output, STDOUT

from commands.utils import directories
from commands.utils.messages import error, info
from utils import directories
from utils.messages import error, info


def snapshot(message):
def snapshot(message, quiet=False):
"""Create a snapshot of the working directory and index."""

if not directories.is_git_repository():
Expand All @@ -26,4 +26,4 @@ def snapshot(message):
with open(os.devnull, 'w') as devnull:
call(['git', 'stash', 'apply', '--quiet'], stdout=devnull, stderr=STDOUT)
else:
info('No local changes to save. No snapshot created.')
info('No local changes to save. No snapshot created.', quiet)
4 changes: 2 additions & 2 deletions bin/commands/tuck.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from utils.messages import error, info


def tuck(files, message=None):
def tuck(files, message=None, quiet=False):
"""Stash specific files."""

# resolve the files to be tucked
Expand Down Expand Up @@ -42,4 +42,4 @@ def tuck(files, message=None):
if staged:
call(reset_command + ['--soft'])

info('Tucked files: ' + ' '.join(files_to_tuck))
info('Tucked files: ' + ' '.join(files_to_tuck), quiet)
4 changes: 2 additions & 2 deletions bin/commands/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from subprocess import check_output, PIPE, Popen

from commands.utils import directories
from commands.utils.messages import error
from utils import directories
from utils.messages import error

_MERGE_CONFIG = 'git config --local branch.{}.merge'
_REMOTE_CONFIG = 'git config --local branch.{}.remote'
Expand Down
7 changes: 4 additions & 3 deletions bin/commands/utils/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def error(message, exit=True):
sys.exit(1)


def info(message):
"""Print a simple info message"""
def info(message, quiet=False):
"""Print a simple info message."""

print(message)
if not quiet:
print(message)
13 changes: 12 additions & 1 deletion bin/git-abandon
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,25 @@ def main():
type=int
)

dry_quiet_group = parser.add_mutually_exclusive_group()

# -d|--dry-run
parser.add_argument(
dry_quiet_group.add_argument(
'-d',
'--dry-run',
help="print the stashes that would be dropped but don't drop them",
action='store_true'
)

# -q|--quiet
dry_quiet_group.add_argument(
'-q',
'--quiet',
help='suppress all non-error output',
action='store_true',
default=False
)

abandon.abandon(**vars(parser.parse_args()))

if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions bin/git-restash
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ def main():
default='stash@{0}'
)

# -q|--quiet
parser.add_argument(
'-q',
'--quiet',
help='suppress all non-error output',
action='store_true',
default=False
)

restash.restash(**vars(parser.parse_args()))

if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions bin/git-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def main():
nargs='?'
)

# -q|--quiet
parser.add_argument(
'-q',
'--quiet',
help='suppress all non-error output',
action='store_true',
default=False
)

snapshot.snapshot(**vars(parser.parse_args()))

if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions bin/git-tuck
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ parser.add_argument(
dest='files'
)

# -q|--quiet
parser.add_argument(
'-q',
'--quiet',
help='suppress all non-error output',
action='store_true',
default=False
)

# check that the remaining args match the format: '-- <files> [<files> ..]
args = parser.parse_args()
if args.files and len(args.files) > 1:
Expand Down
8 changes: 6 additions & 2 deletions man/man1/git-abandon.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-ABANDON" "1" "August 2015" "" ""
.TH "GIT\-ABANDON" "1" "December 2015" "" ""
.
.SH "NAME"
\fBgit\-abandon\fR \- drop a count or range of stashes
.
.SH "SYNOPSIS"
\fBgit abandon\fR [(\fB\-d\fR|\fB\-\-dry\-run\fR)] [\fIstart\fR] \fIend\fR
\fBgit abandon\fR [(\fB\-d\fR|\fB\-\-dry\-run\fR)] [(\fB\-q\fR|\fB\-\-quiet\fR)] [\fIstart\fR] \fIend\fR
.
.br
\fBgit abandon\fR (\fB\-h\fR|\fB\-\-help\fR)
Expand All @@ -33,6 +33,10 @@ The end (exclusive) of the range of stashes to drop\.
Print the stashes that would be dropped but don\'t drop them\.
.
.TP
\fB\-q\fR|\fB\-\-quiet\fR
Suppress all non\-error output\.
.
.TP
\fB\-h\fR|\fB\-\-help\fR
Print a simple help message\.
.
Expand Down
5 changes: 3 additions & 2 deletions man/man1/git-abandon.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/man1/git-abandon.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## SYNOPSIS

`git abandon` [(`-d`|`--dry-run`)] [<start>] <end><br>
`git abandon` [(`-d`|`--dry-run`)] [(`-q`|`--quiet`)] [<start>] <end><br>
`git abandon` (`-h`|`--help`)<br>
`git abandon` (`-v`|`--version`)

Expand All @@ -21,6 +21,9 @@
* `-d`|`--dry-run`:
Print the stashes that would be dropped but don't drop them.

* `-q`|`--quiet`:
Suppress all non-error output.

* `-h`|`--help`:
Print a simple help message.

Expand Down
8 changes: 6 additions & 2 deletions man/man1/git-restash.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-RESTASH" "1" "August 2015" "" ""
.TH "GIT\-RESTASH" "1" "December 2015" "" ""
.
.SH "NAME"
\fBgit\-restash\fR \- restash changes
.
.SH "SYNOPSIS"
\fBgit restash\fR [\fIstash\fR]
\fBgit restash\fR [(\fB\-q\fR|\fB\-\-quiet\fR)] [\fIstash\fR]
.
.br
\fBgit restash\fR (\fB\-h\fR|\fB\-\-help\fR)
Expand Down Expand Up @@ -35,6 +35,10 @@ git stash show \-\-patch | git apply \-\-reverse
The stash whose patch should be reverse applied\. If not supplied, the latest stash will be used\.
.
.TP
\fB\-q\fR|\fB\-\-quiet\fR
Suppress all non\-error output\.
.
.TP
\fB\-h\fR|\fB\-\-help\fR
Print a simple help message\.
.
Expand Down
5 changes: 3 additions & 2 deletions man/man1/git-restash.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/man1/git-restash.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## SYNOPSIS

`git restash` [<stash>]<br>
`git restash` [(`-q`|`--quiet`)] [<stash>]<br>
`git restash` (`-h`|`--help`)<br>
`git restash` (`-v`|`--version`)

Expand All @@ -19,6 +19,9 @@ git stash show --patch | git apply --reverse
* <stash>:
The stash whose patch should be reverse applied. If not supplied, the latest stash will be used.

* `-q`|`--quiet`:
Suppress all non-error output.

* `-h`|`--help`:
Print a simple help message.

Expand Down
8 changes: 6 additions & 2 deletions man/man1/git-snapshot.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-SNAPSHOT" "1" "August 2015" "" ""
.TH "GIT\-SNAPSHOT" "1" "December 2015" "" ""
.
.SH "NAME"
\fBgit\-snapshot\fR \- create a snapshot of the changes in a dirty working directory
.
.SH "SYNOPSIS"
\fBgit snapshot\fR \fImessage\fR
\fBgit snapshot\fR [(\fB\-q\fR|\fB\-\-quiet\fR)] \fImessage\fR
.
.br
\fBgit snapshot\fR (\fB\-h\fR|\fB\-\-help\fR)
Expand Down Expand Up @@ -36,6 +36,10 @@ $ git stash apply
The message to use when creating the underlying stash\. If no message is supplied, the default \fBgit\-stash\fR message is used\.
.
.TP
\fB\-q\fR|\fB\-\-quiet\fR
Suppress all non\-error output\.
.
.TP
\fB\-h\fR|\fB\-\-help\fR
Print a simple help message\.
.
Expand Down
Loading

0 comments on commit 51cd6fa

Please sign in to comment.