Skip to content
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

Add support for the --text option to treat all files as text. #525

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.1.0

- Add support for the `--text` option to treat all files as text.

## 8.0.0

- Add support for multiple patch files for a single package. #474
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ team.

Specify the name for the directory in which to put the patch files.

- `--text`

Treat all files as text files. This is useful when git detects text files as binary ones and returns empty diffs.

#### Nested packages

If you are trying to patch a package at, e.g.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "patch-package",
"version": "8.0.0",
"version": "8.1.0",
"description": "Fix broken node modules with no fuss",
"main": "dist/index.js",
"repository": "github:ds300/patch-package",
Expand Down
20 changes: 20 additions & 0 deletions src/gitDiffArguments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createGitDiffArguments } from "./gitDiffArguments"

const gitDiffTextArgument = "--text"

describe("createGitDiffArguments", () => {

it("should return --text as one of arguments when enforceTextFileType is true", () => {

const enforceTextFileType = true

expect(createGitDiffArguments(enforceTextFileType)).toContain(gitDiffTextArgument)
})

it("shouldn't return --text as one of arguments when enforceTextFileType is false", () => {

const enforceTextFileType = false

expect(createGitDiffArguments(enforceTextFileType)).not.toContain(gitDiffTextArgument)
})
})
21 changes: 21 additions & 0 deletions src/gitDiffArguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { blueBright } from "chalk"

export function createGitDiffArguments(enforceTextFileType: boolean) {

const gitDiffArgs = [
"diff",
"--cached",
"--no-color",
"--ignore-space-at-eol",
"--no-ext-diff",
"--src-prefix=a/",
"--dst-prefix=b/",
]

if (enforceTextFileType) {
console.log(blueBright("Treating all files as text."))
gitDiffArgs.push("--text")
}

return gitDiffArgs
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const argv = minimist(process.argv.slice(2), {
"error-on-warn",
"create-issue",
"partial",
"text",
"",
],
string: ["patch-dir", "append", "rebase"],
Expand Down Expand Up @@ -86,6 +87,7 @@ if (argv.version || argv.v) {
appPath,
argv["use-yarn"] ? "yarn" : null,
)
const enforceTextFileType = !!argv.text;
const createIssue = argv["create-issue"]
packageNames.forEach((packagePathSpecifier: string) => {
makePatch({
Expand All @@ -100,6 +102,7 @@ if (argv.version || argv.v) {
"append" in argv
? { type: "append", name: argv.append || undefined }
: { type: "overwrite_last" },
enforceTextFileType
})
})
} else {
Expand Down
14 changes: 5 additions & 9 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PackageManager } from "./detectPackageManager"
import { removeIgnoredFiles } from "./filterFiles"
import { getPackageResolution } from "./getPackageResolution"
import { getPackageVersion } from "./getPackageVersion"
import { createGitDiffArguments } from "./gitDiffArguments"
import { hashFile } from "./hash"
import {
getPatchDetailsFromCliString,
Expand Down Expand Up @@ -63,6 +64,7 @@ export function makePatch({
patchDir,
createIssue,
mode,
enforceTextFileType,
}: {
packagePathSpecifier: string
appPath: string
Expand All @@ -72,6 +74,7 @@ export function makePatch({
patchDir: string
createIssue: boolean
mode: { type: "overwrite_last" } | { type: "append"; name?: string }
enforceTextFileType: boolean
}) {
const packageDetails = getPatchDetailsFromCliString(packagePathSpecifier)

Expand Down Expand Up @@ -310,16 +313,9 @@ export function makePatch({
// stage all files
git("add", "-f", packageDetails.path)

const gitDiffArgs = createGitDiffArguments(enforceTextFileType)
// get diff of changes
const diffResult = git(
"diff",
"--cached",
"--no-color",
"--ignore-space-at-eol",
"--no-ext-diff",
"--src-prefix=a/",
"--dst-prefix=b/",
)
const diffResult = git(...gitDiffArgs)

if (diffResult.stdout.length === 0) {
console.log(
Expand Down