holygeek / git-number Goto Github PK
View Code? Open in Web Editor NEWUse numbers for dealing with files in git
License: ISC License
Use numbers for dealing with files in git
License: ISC License
please introduce this command which will change directory where chosen file are placed;
#1631 both modified: lib/FrontOffice/Controller/Domain/Service.pm
so
git-number-cd 1631
will 'cd' to directory where Service.pm is:
cd lib/FrontOffice/Controller/Domain/
diff --git a/git-number b/git-number
index 221ba8e..d5f7988 100755
--- a/git-number
+++ b/git-number
@@ -141,10 +141,10 @@ while (scalar @ARGV) {
}
if ( $arg =~ m/^[0-9][0-9]*$/ ) {
- push @args, split("\n", `git-list $arg`);
+ push @args, map{"$ENV{PWD}/$_"} split("\n", `git-list $arg`);
$converted=1;
} elsif ( $arg =~ m/^[0-9][0-9]*-[0-9][0-9]*$/ ) {
- push @args, split("\n", `git-list $arg`);
+ push @args, map{"$ENV{PWD}/$_"} split("\n", `git-list $arg`);
$converted=1;
} else {
if (index($arg, ' ') != -1) {
kes@work ~/work/projects/github-forks/git-number $
With this patch I force git-number
to generate absolute path:
$ ge 2 # with patch
subl /home/kes/s/lib/App/Controller/ConnConfig.pm
$ ge 2 # without patch
subl lib/App/Controller/ConnConfig.pm
This allows me to workaround problem when sublime text editor expand ~s
symlink to full absolute path.
Currently I just expand path unconditionally
$ alias gr
alias gr='gn -c git reset HEAD'
$ alias gn
alias gn='git-number'
$ gr 1
git reset HEAD "lib/MaitreD/Controllers/Country.pm -> etc/Country.pm"
Despite on I wanna to delete 2
file. git-number
tries to delete 1
instead.
Details:
$ pwd -P
/home/kes/work/projects/github-forks/perl5
$ git-number
On branch blead
Your branch is behind 'origin/blead' by 1422 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
1 deleted: pod/perldelta.pod
Untracked files:
(use "git add <file>..." to include in what will be committed)
2 pod/perl5242delta.pod
no changes added to commit (use "git add" and/or "git commit -a")
$ git-number -c rm 2
rm /home/kes/work/projects/github-forks/perl5/pod/perldelta.pod
rm: cannot remove '/home/kes/work/projects/github-forks/perl5/pod/perldelta.pod': No such file or directory
# Failed test 'Status after commit and reset --hard'
# at t/001_git-number.t line 115.
# got: '# On branch master
# nothing to commit, working directory clean
# '
# expected: '# On branch master
# nothing to commit (working directory clean)
# '
Maybe perhaps due to git 1.7/1.8 differences?
When file is opened by $EDITOR
it is opened as ~/s/filename
where s
is symlink to some dir.
But when file is opened with git-number
it is opened as /home/user/s/filename
. The $EDITOR
sees them as two different files. That is ugly.
alias gn="git-number"
alias ge="gn -c $EDITOR"
ge 1 # Here 1 is ~/s/filename
Please do not convert file path to absolute path
For example calling git number add 2-
or git number add -3
rather than git number add 1-3
.
Many thanks in advance!
It would be pretty cool to install this helpful tool via brew install git-number
. BAM, done.
Does the formulae exist? Or, would you like for it to exist, if it doesn't?
I've noticed that other columns are aligned in the output, but the first numbers column is always separated from the second one with one space. Is there some easy way to make it always reserve 2 characters at least so that stuff is aligned nicely?
Thanks!
that is all.
git-number -c git checkout 40_imple<TAB>
expected: work at same manner as git checkout 40_imple<TAB>
Here I run git number out of git repository:
git-number -c rsub --port 52697 file
fatal: Not a git repository (or any of the parent directories): .git
rsub --port Please run git-number first file
There are more than one files specified. Opening only run and ignoring other.
/usr/local/bin/rsub: line 305: Please: Servname not supported for ai_socktype
/usr/local/bin/rsub: line 305: /dev/tcp/localhost/Please: Invalid argument
Unable to connect to TextMate on localhost:Please
Running make test
on macOS 10.13 leads to many failures:
# Using git version 2.13.5 (Apple Git-94)
t/000_setup.t ................ ok
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'fx@bli.(none)')
# Failed test 'Status after commit and reset --hard'
# at t/001_git-number.t line 67.
# 'On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# 1 new file: one.txt
# 2 new file: two.txt
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# 3 deleted: two.txt
#
# '
# doesn't match '(?^:(# )?On branch master
# nothing to commit,? \(?working directory clean\)?
# )'
# Failed test 'git-number status foo.txt'
# at t/001_git-number.t line 76.
# 'On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# 1 new file: one.txt
# 2 new file: two.txt
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# 3 deleted: two.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# 4 foo.txt
#
# '
# doesn't match '(?^ms:Untracked files:.*\n#?1\tfoo.txt\n.*nothing added to commit but untracked files present \(use "git add" to track\))'
# Failed test 'git-number status 1'
# at t/001_git-number.t line 81.
# 'On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: one.txt
#
# '
# doesn't match '(?^ms:Untracked files:.*\n#?\tfoo.txt\n.*nothing added to commit but untracked files present \(use "git add" to track\))'
# Failed test 'git-number -c ls 1'
# at t/001_git-number.t line 89.
# +---+----------+----------+
# | Ln|Got |Expected |
# +---+----------+----------+
# * 1|'one.txt |'foo.txt *
# | 2|' |' |
# +---+----------+----------+
cat: two.txt: No such file or directory
# Failed test ''git-number -c ...' in different dir than 'git-number' was invoked in'
# at t/001_git-number.t line 97.
# +---+-----+---+-----------+
# | Ln|Got | Ln|Expected |
# +---+-----+---+-----------+
# * 1|'' * 1|'Needle\n *
# | | * 2|' *
# +---+-----+---+-----------+
# Looks like you failed 5 tests of 10.
t/001_git-number.t ...........
Dubious, test returned 5 (wstat 1280, 0x500)
Failed 5/10 subtests
t/002_git-list.t ............. ok
t/003_git-id.t ............... ok
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'fx@bli.(none)')
# Failed test 'Modified a file in submodule'
# at t/004_submodule.t line 39.
# 'On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# 1 new file: a.txt
#
# '
# doesn't match '(?^ms:#?1\tmodified: b \(modified content\)\n.*no changes added to commit \(use "git add" and/or "git commit -a"\))'
# Failed test 'Get name of modified submodule using git-list'
# at t/004_submodule.t line 45.
# +---+---------+----------+
# | Ln|Got |Expected |
# +---+---------+----------+
# * 1|'a.txt' |'b' *
# +---+---------+----------+
# Looks like you failed 2 tests of 2.
t/004_submodule.t ............
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/2 subtests
t/005_short_status.t ......... ok
t/006_custom_status_color.t .. ok
t/007_git-id-column.t ........ ok
Test Summary Report
-------------------
t/001_git-number.t (Wstat: 1280 Tests: 10 Failed: 5)
Failed tests: 5-9
Non-zero exit status: 5
t/004_submodule.t (Wstat: 512 Tests: 2 Failed: 2)
Failed tests: 1-2
Non-zero exit status: 2
Files=8, Tests=31, 4 wallclock secs ( 0.04 usr 0.02 sys + 1.91 cusr 2.08 csys = 4.05 CPU)
Result: FAIL
make: *** [test] Error 1
VSCode v1.19.0. (x64, win10)
It's working good in Mac (High Sierra) VSCode v1.19.0.
But git number doesn't work properly after latest update in Win10(x64) VSCode.
gs, ga, gn, of course git number doesn't work too.
[error message in vscode]
fatal: 'number' appears to be a git command, but we were not
able to execute it. Maybe git-number is broken?
I'm using latest git number.
If you add to .gitconfig
[color "status"]
untracked = red bold
you will not able to add files
$ gn
On branch feature/login_form
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
1 modified: XXXX
Untracked files:
(use "git add <file>..." to include in what will be committed)
2 file.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ ga 2
git add "file.txt"
fatal: pathspec 'file.txt' did not match any files
$
After git add "
starting at file.txt"
text is red. It seems git number
put ESC sequence into the command
For consistency:
alias gn='git-number'
alias ga='gn add'
I did a brew update, got git 1.9.0, and git number stopped parsing files. I no longer see any IDs next to changed or modified files, and can't use git number at all.
I'm on Mavericks 10.9.2. Here's the git formula: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/git.rb
I have gone back to 1.8.3.4, and everything works fine. I'd rather have an older version of git than lose git number :)
I have complicated line I've put in shell alias, and can not use it with the -c option. Any time to implement this?
While I am rebasing
$ git status
interactive rebase in progress; onto 3d276f8
Last command done (1 command done):
e ece1d11 Do not query DB if user pass wrong arguments
Next commands to do (3 remaining commands):
pick f6ba33d Setup error if there is no user with supplied login/password
pick d6950f0 In case of errors we should render 'error' template
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'API_for_frontend' on '3d276f8'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working directory clean
I often required to edit files:
commit ece1d1137f0665243a9b9ab9bcd01c3fd61e8b85
Author: Eugen Konkov <[email protected]>
Date: Tue Dec 20 19:36:00 2016 +0200
Do not query DB if user pass wrong arguments
lib/ArtCoin/Controller/Auth.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
It will be handy to display numbers in this case too
This is a cool library, thank you for sharing. Instead of using the aliases posted, I'm using a function which, if parameters are passed on to git functions (e.g. there are more than 1 parameters passed to gn
), then I'm outputting the result of git number -s
when the action is complete. It's handy for me, as I always impulsively check git status
when working with files, so this does it for me. Maybe worth posting in the readme, maybe not. ¯_(ツ)_/¯
https://github.com/jtsternberg/Dot-Files/blob/master/.git-functions#L40-L44
I've been using git-number for a while now, and I just realized that if I alias git to git-number all my favorite git commands like rm work without having to remember another alias.
for bash:
alias git=git-number
Now I don't need a ton of aliases, all the git commands work normally and also with added number syntax!
I haven't found any pitfalls yet, are there any you know of? Is there a reason why this is not suggested in the readme?
Thanks for the great tool!
After new changes to allow argument passthrough for git number -s
, I can't check out files anymore using numbers:
$ git number checkout -- 1
error: pathspec '1' did not match any file(s) known to git.
If you have a crazy file name with bash variable sequences:
Product-${productVersion} Docker (Build ${buildDate}.${buildNumber}).tar
and it shows in git status like this:
Untracked files:
(use "git add <file>..." to include in what will be committed)
1 Product-${productVersion} Docker (Build ${buildDate}.${buildNumber}).tar
And you try to remove it with:
git number -c rm 1
The generated command uses double quotes for the filename. Using single quotes would resolve the issue
Generated Command
git number -c rm "Product-\${productVersion} Docker (Build \${buildDate}.\${buildNumber}).tar"
If the command following git number
is not a Git command, it would be nice if you tried to run the command as a shell command instead.
So for example, I should be able to type git number emacs 1
to open the first file in emacs.
Fast-forward
app/lib/SC/Site/Block/Feed.pm | 9 +++++++++
app/public/_s/css/common/all.css | 7 +++++--
app/public/_s/css/common/common-adaptive.css | 1 +
app/public/_s/css/common/common-old.css | 4 +++-
layouts/common/common.tt | 17 +++++++++++++++--
layouts/common_new/common.tt | 17 +++++++++++++++--
Currently git-number has special handling for arguments with a ' ', '(' or ')' in the name. However there are many other characters that can cause problems, for example '"" or '''.
When outputting the arguments for the command line, the %q type from printf should be used, as this will safely quote all parameters. https://stackoverflow.com/a/6306730/97627
Either that or pass in the arguments to system as parameters rather than as one big string. https://stackoverflow.com/a/3212171/97627
alias gn="git-number"
alias gd="gn -c git diff -b -w --ignore-blank-lines --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+'"
$ gd .
sh: 1: Syntax error: word unexpected
The error is:
$ git-number
error: unknown option `column=never'
usage: git status [options] [--] <filepattern>...
-v, --verbose be verbose
-s, --short show status concisely
-b, --branch show branch information
--porcelain machine-readable output
-z, --null terminate entries with NUL
-u, --untracked-files[=<mode>]
show untracked files, optional modes: all, normal, no. (Default: all)
--ignored show ignored files
--ignore-submodules[=<when>]
ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)
Resolution is commenting out these lines:
https://github.com/holygeek/git-number/blob/master/git-id#L86-L88
# if (! $untracked_in_columns) {
# $status_opt .= " --column=never";
# }
Here is my git version:
$ git --version
git version 1.7.9
git-number
doesn't work when the git-status
command has a custom header color. for example, something like my ~/.gitconfig
:
...
[color "status"]
header = normal dim
...
Any ideas?!
$git status --short --branch
## orm
MM ../DbMapper.pm
M Adapter/Echo.pm
M DataSet.pm
?? ../../conf/local.conf2
?? ../../dbi.pl
?? Data/
?? ../Mojolicious/Plugin/Control/Button.txt
?? ../../public/dashv2/
?? ../../public/downloads/modals.js
?? ../../public/index.html
?? ../../public/profile/modals.js
$ git-number --short
Unknown option: --short
I'm not sure how it could be done, but the depth option on clone is taken as a value to substitute when aliasing git to git-number. Would it be crazy to add an exception to the git-number alogrithm to account for this? Are the other cases?
git clone --depth 1 https://github.com/spark/core-common-lib.git
git clone --depth application/themes/default/dashboard.html.twig https://github.com/spark/core-common-lib.git
Cloning into 'core-common-lib'...
fatal: transport: invalid depth option 'application/themes/default/dashboard.html.twig'
Unexpected end of command stream
How to reproduce
$git-number
1 renamed: abc -> def
2 modified: ../list
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
3 modified: ../README.md
4 modified: ../list
$ git-number -c git reset 1
git reset "abc -> def"
fatal: ambiguous argument 'abc -> def': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ alias gn
alias gn='git-number'
$ gn
On branch design
Your branch is ahead of 'origin/design' by 7 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
1 deleted: ../../../public/assets/bank-logo.png
2 deleted: ../../../public/assets/close-icon.png
3 deleted: ../../../public/assets/disable-icon.png
4 deleted: ../../../public/assets/gilroy-webfont.eot
...
$ gn -c git reset HEAD 1-50
git reset HEAD /home/kes/s/design/dash/dist/. /home/kes/s/design/dash/dist/. /home/kes/s/design/dash/dist/. /home/kes/s/design/dash/dist/. /home/kes/s/design/dash/dist/.
...
EXPECT:
The file name should be ../../../public/assets/bank-logo.png
instead of /home/kes/s/design/dash/dist/.
How to reproduce:
$ alias gl
alias gl='f(){ gn log -w -b -p --ignore-blank-lines --full-history $@; unset -f f; }; f'
$ gl 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- lib/Invoice/Schema/Result/Company.pm
git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ lib/Invoice/Schema/Result/Company.pm
fatal: ambiguous argument 'lib/Invoice/Schema/Result/Company.pm': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
It seems --
is lost.
I expect command to look like: git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- lib/Invoice/Schema/Result/Company.pm
Another issue here it seems that it is not possible to pass the number for lib/Invoice/Schema/Result/Company.pm
file, eg git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- 7
I need to pass file after --
because this file was deleted and does not exists at current working directory, so I need to pass its name after --
.
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.