I have a node script outputting a space-separated list of files to a plain text file, .git-files-to-diff
, and then I'm trying to use that file to create a "proper" git diff in my bash script.
Something like this:
node ./shell-scripts/pre-commit/stage1.mjs;
git diff -- $(cat .pre-commit-cache/.git-files-to-diff)
node ./shell-scripts/pre-commit/stage2.mjs;
The rationale here is to get the beautiful git diff
output from delta. I couldn't figure out anyway to execute git diff
from a node script, so I'm exiting the node script, running it in bash, then resuming in node (rabbit hole)
My file
is something like this - all file specs are quoted and separated by a space:
".does-not-exist1" ".*ignore"
When I run just cat file
it works as expected - just prints list of files... but otherwise, doesn't print anything, no error, nothing...
Reproduce:
cd ~/repos;
rm -rf git-diff-issue;
mkdir git-diff-issue;
cd git-diff-issue;
git init;
touch README.md;
touch other.md;
touch .eslintignore;
touch .git-diff-list;
ls -a;
echo "readme" > README.md;
echo "other" > other.md;
echo "node_modules" > .eslintignore;
echo '".*ignore" "README.md"' > .git-diff-list;
echo "cat file:";
cat .git-diff-list;
git add --intent-to-add README.md .eslintignore .git-diff-list;
echo "full diff:";
git diff;
echo "targeted diff:";
git diff -- ".*ignore" "README.md";
echo "targeted diff with cat:";
git diff -- $(cat .git-diff-list);
Text version of reproduction script running on my machine:
Initialized empty Git repository in /Users/devinrhode2/repos/git-diff-issue/.git/
. .. .eslintignore .git .git-diff-list README.md other.md
cat file:
".*ignore" "README.md"
full diff:
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.git-diff-list b/.git-diff-list
new file mode 100644
index 0000000..524215d
--- /dev/null
+++ b/.git-diff-list
@@ -0,0 +1 @@
+".*ignore" "README.md"
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8178c76
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+readme
targeted diff:
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+node_modules
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8178c76
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+readme
targeted diff with cat:
git-diff-issue $
Notice there is no output on the final command.