Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Fix theme pull to no longer add empty lines on Windows (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro authored Jan 18, 2022
1 parent ef127d0 commit 245d64a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h

## [Unreleased]

### Fixed
* [#1937](https://github.com/Shopify/shopify-cli/pull/1937): Fix `theme pull` to no longer add empty lines on Windows

## 2.9.0

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions lib/shopify_cli/theme/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(path, root)

def read
if text?
path.read
path.read(universal_newline: true)
else
path.read(mode: "rb")
end
Expand All @@ -27,7 +27,7 @@ def read
def write(content)
path.parent.mkpath unless path.parent.directory?
if text?
path.write(content)
path.write(content, universal_newline: true)
else
path.write(content, 0, mode: "wb")
end
Expand Down
75 changes: 75 additions & 0 deletions test/shopify-cli/theme/file_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true
require "test_helper"
require "shopify_cli/theme/file"

module ShopifyCLI
module Theme
class FileTest < Minitest::Test
def setup
super
@file = File.new("path", root)
@file.stubs(:path).returns(path)
end

def test_read_when_file_is_a_text
@file.stubs(:text?).returns(true)

@path.expects(:read).with(universal_newline: true)
@file.read
end

def test_read_when_file_is_not_a_text
@file.stubs(:text?).returns(false)

@path.expects(:read).with(mode: "rb")
@file.read
end

def test_write_when_file_parent_is_not_a_directory
@path.parent.stubs(:directory?).returns(false)
@path.stubs(:write)

@path.parent.expects(:mkpath)
@file.write("content")
end

def test_write_when_file_parent_is_a_directory
@path.parent.stubs(:directory?).returns(true)
@path.stubs(:write)

@path.parent.expects(:mkpath).never
@file.write("content")
end

def test_write_when_file_is_a_text
@path.parent.stubs(:directory?).returns(true)
@file.stubs(:text?).returns(true)

@path.expects(:write).with("content", universal_newline: true)
@file.write("content")
end

def test_write_when_file_is_not_a_text
@path.parent.stubs(:directory?).returns(true)
@file.stubs(:text?).returns(false)

@path.expects(:write).with("content", 0, mode: "wb")
@file.write("content")
end

private

def path
@path = mock
@path.stubs(:parent).returns(mock)
@path
end

def root
@root = mock
@root.stubs(:expand_path).returns(ShopifyCLI::ROOT)
@root
end
end
end
end

0 comments on commit 245d64a

Please sign in to comment.