Last active
December 10, 2020 09:38
-
-
Save tomdl89/d1c68aac21a66ec656b848503188a491 to your computer and use it in GitHub Desktop.
Magit to stage (intent-to-add only) untracked files on save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun auto-stage-untracked-file () | |
"Add an empty version of the currently-visited file to the index | |
iff it is in a git repo, but untracked." | |
(when (and (magit-git-dir) | |
(not (magit-file-tracked-p (buffer-file-name))) | |
this-command ; nil for auto-save | |
(y-or-n-p "Add (intent-to-add) file to git index?")) | |
(magit-run-git "add" "--intent-to-add" "--" (buffer-file-name)))) | |
(add-hook 'after-save-hook 'auto-stage-untracked-file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment