brickster / git-commands Goto Github PK
View Code? Open in Web Editor NEWA collection of custom git commands
License: MIT License
A collection of custom git commands
License: MIT License
file ...
Files to be tucked. The files can be absolute or specified using pathspecs.
While snapshot used tuck under the hood to create a snapshot of the specific files, it shouldn't be described as a tuck.
$ git log --oneline develop..HEAD
f046c5f Update properties
$ git log --oneline master..HEAD
f046c5f Update properties
7b8db15 Update changelog
$ git config --local git-changes.default-branch
develop
$ git changes -b develop
f046c5f Update properties
$ git changes
f046c5f Update properties
7b8db15 Update changelog
The last two commands should be identical.
$ git init testing
$ cd testing
$ git state
Traceback (most recent call last):
File "/Users/User/Development/python/git-commands/bin/git-state", line 256, in <module>
main()
File "/Users/User/Development/python/git-commands/bin/git-state", line 253, in main
state.state(**vars(parser.parse_args()))
File "/Users/User/Development/python/git-commands/bin/commands/state.py", line 144, in state
for section_info in sections:
UnboundLocalError: local variable 'sections' referenced before assignment
[user]
# that's me
name = Marcus
# init details
[init]
templatedir = /Users/marcusrosenow/.gittemplate/template
becomes
[init]
templatedir = /Users/marcusrosenow/.gittemplate/template
[user]
# that's me
name = Marcus
# init details
This is true of whitespace, as well.
Specifically, for non-informative commands.
--dry-run
. That wouldn't make sense.It works with any value. Not just ints.
Use git -c color.status=<color> status
to change coloring options rather than settings the configuration itself.
When the branch has no upstream and git-upstream is used, a blank line is printed.
$ git status --short --branch
## fix-upstream
$ git upstream
$
It should print nothing.
If an extension contains a quoted string, the underlying command isn't executed correctly.
$ git config git-state.extensions.print-message "printmessage \"this is the message\""
$ git state -STBLR
# print-message
message: this
$
Use shlex
so that quotes strings are maintained:
import shlex
command = shlex.split('printmessage "this is the message"')
$ touch file.txt
$ git status --short
?? file.txt
$ git stash save -u
Saved working directory and index state WIP on gitignore: 3e72f3b Remove now ignored file
HEAD is now at 3e72f3b Remove now ignored file
$ git stash apply
Already up-to-date!
On branch gitignore
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git restash
fatal: unrecognized input
$ git status --short
?? file.txt
It would be nice to be able to create a snapshot of only a few files.
$ git snapshot -- *.txt README.md
$ git state -LBTR --no-color > ~/Desktop/tmp.txt
$ cat -e ~/Desktop/tmp.txt
# status ^[[0m(master...origin/master)$
$
FlagAsValue
is unnecessary since out of the box argparse options have the same result.
For instance:
# -r|--remote
branch_group.add_argument(
'-r',
'--remote',
help='show the commits between the local and remote head',
action=flag_as_value(upstream.upstream(True)),
nargs=0,
dest='branch'
)
is equivalent to:
# -r|--remote
branch_group.add_argument(
'-r',
'--remote',
help='show the commits between the local and remote head',
action='store_const',
dest='branch',
const=upstream.upstream(True)
)
When git-state prints the status section in color it needs to write to the color.ui configuration. If the user didn't have any other color settings, the section is left empty in the config. Each execution adds a new empty section.
After five executions the local config file might look like this:
[git-state "reflog"]
show = false
[color]
[color]
[color]
[color]
[color]
The man pages for git-tuck
and main README.md
contain the following:
Used to stash specific files rather than the all-or-thing style of git stash.
It should be all-or-nothing
.
[alias]
# Merge GitHub pull request on top of the `master` branch
mpr = "!f() { \
if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \
git fetch origin refs/pull/$1/head:pr/$1 && \
git rebase master pr/$1 && \
git checkout master && \
git merge pr/$1 && \
git branch -D pr/$1 && \
git commit --amend -m \"$(git log -1 --pretty=%B)\n\nCloses #$1.\"; \
fi \
}; f"
The problem is with the newlines (\n
) and not the line continuations (\
).
[alias]
[alias]
c = commit
becomes
[alias]
c = commit
Like git changes associate <branch>
, the branch argument should be positional and optional.
$ git changes view master # rather than -b master
FILE OPTIONS
Some subcommands can be limited to a specific file. The valid options are:
-- Use local config file.
local
It should be:
FILE OPTIONS
Some subcommands can be limited to a specific file. The valid options are:
--local
Use local config file.
Many, if not all, man pages say something similar to:
-h|--help
Display git-abandon man page.
This isn't true anymore. As of the Python re-write, -h|--help
will print a help message.
Using colorama will allow coloring on Windows machines, as well.
from colorama import Fore
# ...
title = '{no_color}({green}master{no_color})'.format(no_color=Fore.RESET, green=Fore.GREEN)
Like git-restash, the following should man pages should have see-alsos to their related commands:
The default stash message using tuck references a commit that is temporarily created during the tuck operation.
$ git log --oneline
5968ba1 Edit readme
3149cb4 Add files
97d7bcc Initial commit
$ git status --short
M README.md
M file1.txt
M file2.txt
$ git tuck -- file*.txt
Tucked files: file1.txt file2.txt
$ git stash list --oneline
698d871 refs/stash@{0}: WIP on master: aebd142 TUCK: unstaged
Ideally the message would be based on the HEAD commit before the command is executed:
698d871 refs/stash@{0}: WIP on master: 5968ba1 Edit readme
Given branch contributing-documentation
and prior merge base master
, calling git changes master --diff
or git changes master --stat
will show changes from master
.
$ git log --oneline
743bc66 Fix documentation typo
916b18d Update documentation
b2c7c4b Initial commit
$ git show --stat
commit 743bc666f7d135bb3a5570dcee37e17114962234
Author: Marcus Rosenow <[email protected]>
Date: Thu Mar 24 11:04:46 2016 -0500
Fix documentation typo
README.md | 2 --
1 file changed, 2 deletions(-)
$ git checkout contributing-documentation
Switched to branch 'contributing-documentation'
$ git log --oneline
916b18d Update documentation # NOTE: one behind master
b2c7c4b Initial commit
$ git changes # no changes
$ git changes --stat # but stat shows changes
README.md | 2 ++
1 file changed, 2 insertions(+)
$
$ git status --short --branch
## testing.123
$ git changes
error: 'error: invalid key: git-changes.associations.testing.123' is not a valid branch
If the user has a color.ui
setting prior to running git state
, it's removed upon execution.
Rather than only getting the upstream for the current branch, add the ability to specify the branch:
$ git upstream --branch fix-issue
The makefile is missing newer commands and doesn't copy the modules.
The branch flag is missing the argument name:
-b|--branch
Show the commits between HEAD and branch. When not specified, master is used.
It should be:
-b|--branch <branch>
Show the commits between HEAD and branch. When not specified, master is used.
Including "status" in a custom order does nothing.
$ git state --order status log
# log
38ed6ca Merge branch 'order-option'
a927e24 Update changelog
b59db27 Update documentation
1bf6fc3 Add a flag to define section order
ad502ea Fix changelog
880adbe Merge branch 'custom-ordering'
af47718 Update changelog
c6b7dc8 Update documentation
afc5348 Add custom section ordering
326af15 Merge branch 'extension-name'
# status (master...origin/master)
# branches
* master 38ed6ca [origin/master] Merge branch 'order-option'
Add the option to show a clean directory message rather then nothing. Similar to git status
:
$ git state -BRTL
# status (master...origin/master)
nothing to commit, working directory clean
Make it configurable using git-state.status.show-clean-message <bool>
Rather than having to specify --debug=~/.git-commands.log
with each command, a global option would be used to always log.
$ git config --global git-commands.log "~/.git-commands.log"
This may also make a --no-debug
flag useful.
# aliases
[alias]
c = commit
$ git settings cleanup ~/Desktop/config_copy
Traceback (most recent call last):
File "/Users/marcus/Development/python/git-commands/bin/git-settings", line 146, in <module>
main()
File "/Users/marcus/Development/python/git-commands/bin/git-settings", line 143, in main
func(**args)
File "/Users/marcus/Development/python/git-commands/bin/commands/settings.py", line 161, in cleanup
config[key] += [line + os.linesep]
KeyError: None
If git snapshot
is used when the working tree only contains untracked files then Already up-to-date!
is printed. This makes it sound like nothing happened.
$ git status --short
?? CONRIBUTING.md
$ git snapshot
Already up-to-date!
The final line of a pop reads:
Dropped stash@{2} (c7aab1815f8870bcd4a00c09f0720dd11a0bb7ac)
it should read:
Dropped snapshot@{2} (c7aab1815f8870bcd4a00c09f0720dd11a0bb7ac)
When there are no keys for a section, git settings list
prints a blank line.
$ git settings destroy color # removes from local, global, and system
$ git settings list color
$
It should print nothing.
Rather than printing the tucked files:
Tucked files: file1.txt CHANGELOG.md
Print something similar to git-stash
:
Saved working directory and index state WIP on master: a7834c6 Initial commit
HEAD is now at a7834c6 Initial commit
Nothing changes for the following config file:
[git-state "extensions"]
[rebase]
autosquash = true
Long options should have the format --option[=<value>]
. Current long options are in the format --option [<value>]
.
git-state.log.count int
The default log length. Can be overridden using the -d|--log count option.
Default: 10
The short option is -l
not -d
.
color.ui string
Determines whether or not colors are printed in the output. Options --color and --no-color override this value.
Default: auto
The color flag supports a <when>
option and should be --color [<when>]
.
$ git state
error: could not lock config file .git/config: No such file or directory
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "/Users/Marcus/Development/bash/git-commands/bin/git-state", line 232, in <module>
main()
File "/Users/Marcus/Development/bash/git-commands/bin/git-state", line 229, in main
state.state(**vars(parser.parse_args()))
File "/Users/Marcus/Development/bash/git-commands/bin/commands/state.py", line 119, in state
status = check_output(['git', 'status', '--short', '--untracked-files=all', '--branch']).splitlines()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['git', 'status', '--short', '--untracked-files=all', '--branch']' returned non-zero exit status 128
$ git changes associate -b develop --quiet
$ git changes unassociate --prune --quiet
Empty sections should still be printed with including --show-empty
. Currently, they are omitted.
When using a pathspec, the output text prints more than is should:
$ ls
README.md file1.txt file2.txt
$ git status --short
M README.md
?? file2.txt
$ git tuck -- *.txt
Tucked files: file2.txt file1.txt
$ git diff --name-only stash@{0}
README.md
file1.txt
wasn't stashed but shouldn't be in the output either. While #31 will make this irrelevant. The fact that unrelated files are in the file list is worth looking into. It could cause other issues.
Allow the user to decide the order each section is printed.
For instance:
# status (Initial commit on master)
fatal: bad default revision 'HEAD'
# log
# branches
Ideally, git-state
would gracefully handle an empty repo and output something like:
# status (master...none)
Empty repo.
Since cleanup currently doesn't support --system
, --global
, or --local
, it's effectively independent of a specific repository and should run as such.
$ pwd
/Users/marcus/Desktop
$ git settings cleanup '~/.gitconfig'
error: '/Users/marcus/Desktop' not a git repository
The underlying issue is how the default command line arguments are loaded.
$ git state --tags
# status (state-tags)
nothing to commit, working directory is clean
# tags
c7153eb v0.1.0
9d02c56 v0.2.0
29182eb v0.3.0
b8cd205 v0.4.0
$
Currently:
$ git changes HEAD^
error: 'HEAD^' is not a valid branch
Should be:
$ git log --oneline
743bc66 Fix documentation typo
916b18d Update documentation
b2c7c4b Initial commit
$ git changes
$ git changes HEAD^
743bc66 Fix documentation typo
The Python re-write made it so config values need to be case sensitive. Therefore, setting the following state setting:
$ git config --local git-state.reflog.show true
causes an error when running the command.
The case shouldn't matter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.