Created
February 24, 2016 22:45
-
-
Save sideshowcoder/ae1f6b9ab4e5944472c1 to your computer and use it in GitHub Desktop.
Switching github users when using magit
This file contains hidden or 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
| ;; make sure we always use the correct user for git when using magit, and save it off for later as well | |
| ;; in the local user property for the repo | |
| (require 'subr-x) | |
| (defun yammer-git-repo-p () | |
| (string-match "int.yammer.com" (shell-command-to-string "git config --get remote.origin.url"))) | |
| (defun yammer-git-property (prop) | |
| (string-trim (shell-command-to-string (format "git config --get %s" prop)))) | |
| (defcustom yammer-git-user-key | |
| "user.yam-name" | |
| "key for the global git property which holds the internal github user, default: user.yam-name") | |
| (defcustom yammer-git-email-key | |
| "user.yam-email" | |
| "key for the global git property which holds the internal github email, default: user.yam-email") | |
| (defun local-user-overwrite-set-p () | |
| (not (string-empty-p (shell-command-to-string "git config --local --get user.name")))) | |
| (defun set-yammer-user-for-git () | |
| (interactive) | |
| (if (yammer-git-repo-p) | |
| (if (not (local-user-overwrite-set-p)) | |
| (let ((name (yammer-git-property yammer-git-user-key)) | |
| (email (yammer-git-property yammer-git-email-key))) | |
| (message (format "Setting user.name %s and user.email %s" name email)) | |
| (shell-command (format "git config --local --add user.name %s" name)) | |
| (shell-command (format "git config --local --add user.email %s" email))) | |
| (message "local user overwrite already set")) | |
| (message "Not a yammer git repository"))) | |
| (add-hook 'magit-mode-hook #'set-yammer-user-for-git) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment