Skip to content

saving colons in stash messages from crashes #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

require 'bundler/setup'

`git config --global user.email "git@example.com"` if `git config user.email`.empty?
`git config --global user.name "GitExample"` if `git config user.name`.empty?
`git config --global init.defaultBranch master` if `git config init.defaultBranch`.empty?
`git config --global user.email "git@example.com"` if `git config --global user.email`.empty?
`git config --global user.name "GitExample"` if `git config --global user.name`.empty?
`git config --global init.defaultBranch master` if `git config --global init.defaultBranch`.empty?

project_root = File.expand_path(File.join(__dir__, '..'))

Expand Down
11 changes: 11 additions & 0 deletions bin/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -e
test "$#" -ne 0 && echo "Unsupported args: $@" >&2 && exit 145
cd "$( dirname "${BASH_SOURCE[0]}" )"/..

export COMPOSE_FILE=tests/docker-compose.yml
export COMPOSE_PROJECT_NAME=ruby-git_dev

docker-compose rm -svf
docker-compose build --force-rm

docker-compose run --rm tester && docker-compose rm -svf || ( docker-compose logs && exit 1 )
6 changes: 4 additions & 2 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,10 @@ def stashes_all
if File.exist?(filename)
File.open(filename) do |f|
f.each_with_index do |line, i|
m = line.match(/:(.*)$/)
arr << [i, m[1].strip]
_, msg = line.split("\t")
# NOTE this logic may be removed/changed in 3.x
m = msg.match(/^[^:]+:(.*)$/)
arr << [i, (m ? m[1] : msg).strip]
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ruby

WORKDIR /ruby-git


ADD Gemfile git.gemspec .git* ./
ADD lib/git/version.rb ./lib/git/version.rb
RUN bundle install

ADD . .

ENTRYPOINT ["bundle", "exec"]
CMD ["bin/test"]
5 changes: 5 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
tester:
build:
context: ..
dockerfile: tests/Dockerfile
103 changes: 103 additions & 0 deletions tests/units/test_stashes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,107 @@ def test_stashes_all
assert(stashes[0].include?('testing-stash-all'))
end
end
test 'Git::Lib#stashes_all' do
in_bare_repo_clone do |g|
assert_equal(0, g.branch.stashes.size)
new_file('test-file1', 'blahblahblah1')
new_file('test-file2', 'blahblahblah2')
assert(g.status.untracked.assoc('test-file1'))

g.add

assert(g.status.added.assoc('test-file1'))

g.branch.stashes.save('testing-stash-all')

# puts `cat .git/logs/refs/stash`
# 0000000000000000000000000000000000000000 b9b008cd179b0e8c4b8cda35bac43f7011a0836a James Couball <jcouball@yahoo.com> 1729463252 -0700 On master: testing-stash-all

stashes = assert_nothing_raised { g.lib.stashes_all }

expected_stashes = [
[0, 'testing-stash-all']
]

assert_equal(expected_stashes, stashes)
end
end

test 'Git::Lib#stashes_all - stash message has colon' do
in_bare_repo_clone do |g|
assert_equal(0, g.branch.stashes.size)
new_file('test-file1', 'blahblahblah1')
new_file('test-file2', 'blahblahblah2')
assert(g.status.untracked.assoc('test-file1'))

g.add

assert(g.status.added.assoc('test-file1'))

g.branch.stashes.save('saving: testing-stash-all')

# puts `cat .git/logs/refs/stash`
# 0000000000000000000000000000000000000000 b9b008cd179b0e8c4b8cda35bac43f7011a0836a James Couball <jcouball@yahoo.com> 1729463252 -0700 On master: saving: testing-stash-all

stashes = assert_nothing_raised { g.lib.stashes_all }

expected_stashes = [
[0, 'saving: testing-stash-all']
]

assert_equal(expected_stashes, stashes)
end
end

test 'Git::Lib#stashes_all -- git stash message with no branch and no colon' do
in_temp_dir do
`git init`
`echo "hello world" > file1.txt`
`git add file1.txt`
`git commit -m "First commit"`
`echo "update" > file1.txt`
commit = `git stash create "stash message"`.chomp
# Create a stash with this message: 'custom message'
`git stash store -m "custom message" #{commit}`

# puts `cat .git/logs/refs/stash`
# 0000000000000000000000000000000000000000 0550a54ed781eda364ca3c22fcc46c37acae4bd6 James Couball <jcouball@yahoo.com> 1729460302 -0700 custom message

git = Git.open('.')

stashes = assert_nothing_raised { git.lib.stashes_all }

expected_stashes = [
[0, 'custom message']
]

assert_equal(expected_stashes, stashes)
end
end

test 'Git::Lib#stashes_all -- git stash message with no branch and explicit colon' do
in_temp_dir do
`git init`
`echo "hello world" > file1.txt`
`git add file1.txt`
`git commit -m "First commit"`
`echo "update" > file1.txt`
commit = `git stash create "stash message"`.chomp
# Create a stash with this message: 'custom message'
`git stash store -m "testing: custom message" #{commit}`

# puts `cat .git/logs/refs/stash`
# 0000000000000000000000000000000000000000 eadd7858e53ea4fb8b1383d69cade1806d948867 James Couball <jcouball@yahoo.com> 1729462039 -0700 testing: custom message

git = Git.open('.')

stashes = assert_nothing_raised { git.lib.stashes_all }

expected_stashes = [
[0, 'custom message']
]

assert_equal(expected_stashes, stashes)
end
end
end