Skip to content

Commit 018d919

Browse files
authored
Fix bug when grepping lines that contain numbers surrounded by colons (#566)
Signed-off-by: James Fairbairn <jamesaf112@gmail.com>
1 parent c04d16e commit 018d919

File tree

14 files changed

+31
-19
lines changed

14 files changed

+31
-19
lines changed

lib/git/lib.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def grep(string, opts = {})
419419

420420
hsh = {}
421421
command_lines('grep', grep_opts).each do |line|
422-
if m = /(.*)\:(\d+)\:(.*)/.match(line)
422+
if m = /(.*?)\:(\d+)\:(.*)/.match(line)
423423
hsh[m[1]] ||= []
424424
hsh[m[1]] << [m[2].to_i, m[3]]
425425
end

tests/files/working/colon_numbers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Grep regex doesn't like this:4342: because it is bad

tests/files/working/dot_git/index

174 Bytes
Binary file not shown.

tests/files/working/dot_git/logs/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad144323156
7979
6f09de178a27f7702c37907fd614c3c122d33c30 faf8d899a0f123c3c5def10857920be1c930e8ed Scott Chacon <schacon@gmail.com> 1378910110 -0400 commit (merge): Merge commit '4ce44a75510cbfe200b131fdbcc56a86f1b2dc08' into cherry
8080
faf8d899a0f123c3c5def10857920be1c930e8ed 5e392652a881999392c2757cf9b783c5d47b67f7 Scott Chacon <schacon@gmail.com> 1378910135 -0400 checkout: moving from cherry to master
8181
5e392652a881999392c2757cf9b783c5d47b67f7 5e53019b3238362144c2766f02a2c00d91fcc023 Scott Chacon <schacon@gmail.com> 1378910138 -0400 checkout: moving from master to git_grep
82+
5e53019b3238362144c2766f02a2c00d91fcc023 46abbf07e3c564c723c7c039a43ab3a39e5d02dd Scott Chacon <schacon@gmail.com> 1647231179 +1300 commit: add example for grep with colon and numbers

tests/files/working/dot_git/logs/refs/heads/git_grep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
44
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
55
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
6+
5e53019b3238362144c2766f02a2c00d91fcc023 46abbf07e3c564c723c7c039a43ab3a39e5d02dd Scott Chacon <schacon@gmail.com> 1647231179 +1300 commit: add example for grep with colon and numbers

tests/files/working/dot_git/objects/46/abbf07e3c564c723c7c039a43ab3a39e5d02dd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x��Qj�0D��S��H+�A(��'X�V��������G��0<�I-e��zS"Y�Ɯ2�ėe�����#K����9��с��uq��/>��&�9�l�Q�M�e��𳯵����ᶲ���+_����!�|� ӌ޹9»�֚A�a��l������7=����À�dz,��/�RL
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5e53019b3238362144c2766f02a2c00d91fcc023
1+
46abbf07e3c564c723c7c039a43ab3a39e5d02dd
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
46abbf07e3c564c723c7c039a43ab3a39e5d02dd

0 commit comments

Comments
 (0)