question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

git cz -a just differently broken now

See original GitHub issue

Hello there, thanks for this project. I’ve really enjoyed getting changelogs out of my commit messages. I think a recent change to git cz -a (to fix a perhaps over exuberant git add .) has unfortunately just broken things differently. It’s late where I am, so I’ll have to try and come up with an example repo tomorrow, but I’m currently running into an issue where I get the following output in a terminal:

$ git --version
git version 2.18.0
$ node --version
v8.11.3
$ npm --version
6.2.0
$ git status
On branch feat/whatever
Your branch is up to date with 'origin/feat/whatever'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   src/index.html
        modified:   src/main.css

no changes added to commit (use "git add" and/or "git commit -a")
$ git cz -a
No files added to staging! Did you forget to run git add?
$ git commit -am "feat(html): whatever"
[feat/something-idk 89f79ac] feat(html): whatever
 2 files changed, 2 insertions(+)

So, it seems to me something is still not quite right with the -a flag. Thanks again for your help. I’ll be happy to try and test out any steps anyone might recommend for me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mysterycommandcommented, Jul 19, 2018

Okay, here are some repro steps and a possible solution (though I don’t know enough about how other people use Git to know if there are any ramifications to my approach):

Repro:

~/Sites/spikes/cz-cli
12:15:00 $ git init && yarn init -y
Initialized empty Git repository in ~/Sites/spikes/cz-cli/.git/
yarn init v1.7.0
warning The yes flag has been set. This will automatically answer yes to all questions, which may have security implications.
success Saved package.json
✨  Done in 0.11s.

~/Sites/spikes/cz-cli (master #%)
12:15:50 $ git add package.json

~/Sites/spikes/cz-cli (master +)
12:15:57 $ git commit -am "chore: git init && yarn init -y"
[master (root-commit) 14cad29] chore: git init && yarn init -y
 1 file changed, 7 insertions(+)
 create mode 100644 package.json

~/Sites/spikes/cz-cli (master)
12:15:58 $ echo "node_modules" > .gitignore

~/Sites/spikes/cz-cli (master %)
12:16:18 $ git add .gitignore

~/Sites/spikes/cz-cli (master +)
12:16:25 $ git commit -am "chore: ignore node_modules"
[master b583ffa] chore: ignore node_modules
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore

~/Sites/spikes/cz-cli (master)
12:16:43 $ yarn add -D commitizen cz-conventional-changelog

# =======================================
#              REMOVED YARN LOGS FOR SPACE
# =======================================

~/Sites/spikes/cz-cli (master *%)
12:17:33 $ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        yarn.lock

no changes added to commit (use "git add" and/or "git commit -a")

~/Sites/spikes/cz-cli (master *%)
12:17:38 $ git add yarn.lock

~/Sites/spikes/cz-cli (master +)
12:17:44 $ git commit -am "chore: add commitizen and cz-conventional-changelog to dev-deps"
[master ad04fc9] chore: add commitizen and cz-conventional-changelog to dev-deps
 2 files changed, 963 insertions(+), 1 deletion(-)
 create mode 100644 yarn.lock

# =======================================
#  ADD COMMITIZEN CONFIG TO PACKAGE.JSON
# =======================================

~/Sites/spikes/cz-cli (master)
12:18:06 $ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")

~/Sites/spikes/cz-cli (master *)
12:19:24 $ git diff
diff --git a/package.json b/package.json
index 97b6eb9..91fef3d 100644
--- a/package.json
+++ b/package.json
@@ -7,5 +7,10 @@
   "devDependencies": {
     "commitizen": "^2.10.1",
     "cz-conventional-changelog": "^2.1.0"
+  },
+  "config": {
+    "commitizen": {
+      "path": "cz-conventional-changelog"
+    }
   }
 }

~/Sites/spikes/cz-cli (master *)
12:19:25 $ git commit -am "config: add commitizen config to package.json"
[master 2c2d272] config: add commitizen config to package.json
 1 file changed, 5 insertions(+)

~/Sites/spikes/cz-cli (master)
12:19:50 $ touch foo.txt

~/Sites/spikes/cz-cli (master %)
12:20:05 $ git add foo.txt

~/Sites/spikes/cz-cli (master +)
12:20:17 $ git commit -am "feat: foo.txt"
[master d2b899c] feat: foo.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo.txt

~/Sites/spikes/cz-cli (master)
12:20:23 $ echo "bar" > foo.txt

~/Sites/spikes/cz-cli (master *)
12:20:32 $ git diff
diff --git a/foo.txt b/foo.txt
index e69de29..5716ca5 100644
--- a/foo.txt
+++ b/foo.txt
@@ -0,0 +1 @@
+bar

~/Sites/spikes/cz-cli (master *)
12:20:36 $ git cz -a
No files added to staging! Did you forget to run git add?

~/Sites/spikes/cz-cli (master *)
12:20:42 $ git commit -am "feat: add bar to foo.txt"
[master a4e286e] feat: add bar to foo.txt
 1 file changed, 1 insertion(+)

I think the problem is here src/commitizen/staging.js#L9 … isClean should not run git diff with the --cached flag. Here’s a couple more steps to verify that it would behave as I’d expect if that flag were removed:

~/Sites/spikes/cz-cli (master)
12:21:01 $ touch baz.txt

~/Sites/spikes/cz-cli (master %)
12:31:20 $ echo "qux" > foo.txt

~/Sites/spikes/cz-cli (master *%)
12:31:29 $ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   foo.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        baz.txt

no changes added to commit (use "git add" and/or "git commit -a")

~/Sites/spikes/cz-cli (master *%)
12:31:32 $ git diff --cached --name-only

~/Sites/spikes/cz-cli (master *%)
12:32:02 $ git diff --name-only
foo.txt

Without the --cached flag Git lists the expected/tracked list of files which would return false, and the commit operation would run with the appropriate passed-in flags. If you think that’s a viable solution I’d be happy to open a PR some time later this evening. Please let me know what you think!

✨❤️🌟

1reaction
mysterycommandcommented, Jul 18, 2018

Related to #376 and #471

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update to esLint on Angular breaks commitlint - Stack Overflow
Now when I run npx git-cz I get a different set of types for "type of commit". I get Fix, Update, Breaking, Docs,...
Read more >
Do you keep a tidy Git commit history? | by Ali Haydar - Medium
I just needed to review the project changes on other occasions, and I would appreciate clear, concise commit messages. Some of the messages...
Read more >
hyphens - CSS: Cascading Style Sheets - MDN Web Docs
Words are not broken at line breaks, even if characters inside the words suggest line break points. Lines will only wrap at whitespace....
Read more >
Broken Links - Open Government Partnership
Broken Links: Open Data to Advance Accountability and Combat Corruption offers an overview of the state of open data against political corruption in...
Read more >
git push fatal failed - Super User
change owner on server; Error "PUT error: curl result=22, HTTP code=403" has gone.. now only says git-http-push failed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found