Closed KES777 closed 7 years ago
This was done intentionally. The reason was so that the file can be referred to (by their numbers) from a different directory than where git number
was ran. See commit https://github.com/holygeek/git-number/commit/8ffa6a6a.
For example if the "root" of the git repo is at /some/path
and you do git number
in /some/path/three/directories/deep
then doing git number -c vi 1 2 3
will work regardless of whether it is run from /some/path
or /some/path/three
or /some/path/three/directories
or /some/path/three/directories/deep
.
Yes, you should use absolute
path. But do not convert it to physical
For example compare pwd
and pwd -P
with symlink in the path.
Also you may use absolute path only for subdirectories and not for repository root
This patch may do what you want - it forks out pwd
to get the working directory with symlinks intact, instead of using getcwd
syscall via perl's Cwd::getcwd
. All the tests at the tip of master pass so it seems to work fine, but fork()
is more expensive than getcwd()
so there's that.:
$ git diff
diff --git a/git-id b/git-id
index ea99cdd..df7ca1e 100755
--- a/git-id
+++ b/git-id
@@ -98,7 +98,8 @@ open my $cache, ">$gitids"
or die "Error: $!";
# Headers
-print $cache "cwd: " . getcwd . "\n";
+my $cwd = `pwd`;
+print $cache "cwd: $cwd";
print $cache "status-format: $status_format\n";
print $cache "\n";
diff --git a/git-list b/git-list
index 46507af..d5c0b9c 100755
--- a/git-list
+++ b/git-list
@@ -5,7 +5,7 @@
use strict;
use warnings;
use File::Spec;
-use Cwd qw/getcwd abs_path/;
+use Cwd qw/abs_path/;
=pod
@@ -77,7 +77,7 @@ sub get_file_list {
open my $cache, "<$gitids" or die "Error: $!";
my $headers = read_headers($cache);
- my $cwd = getcwd();
+ chomp(my $cwd = `pwd`);
my $needfixdir = 0;
if ($headers->{cwd} ne $cwd) {
$needfixdir = 1;
sorry. this did not help. it seems the issue with sublime text
I resolve task with next patch:
diff --git a/git-number b/git-number
index 440179f..f3cf1ac 100755
--- a/git-number
+++ b/git-number
@@ -138,10 +138,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) {
Maybe it will be useful to implement some option.
Now git-number
run the command as I want:
export EDITOR="subl"
alias gn="git-number"
alias ge="gn -c $EDITOR"
$ ge 4 6
subl /home/kes/s/lib/../templates/form/buy.html.ep /home/kes/s/lib/../templates/server/api.json
instead of:
subl ../templates/form/buy.html.ep ../templates/server/api.json
When file is opened by
$EDITOR
it is opened as~/s/filename
wheres
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.Please do not convert file path to absolute path