Support for git init
This commit is contained in:
parent
f89a045282
commit
9db7719b96
1 changed files with 33 additions and 10 deletions
43
magit.el
43
magit.el
|
@ -251,7 +251,7 @@ Many Magit faces inherit from this one by default."
|
|||
nil)))
|
||||
|
||||
(defun magit-read-top-dir ()
|
||||
(magit-get-top-dir
|
||||
(file-name-as-directory
|
||||
(read-directory-name "Git repository: "
|
||||
(magit-get-top-dir default-directory))))
|
||||
|
||||
|
@ -1656,21 +1656,44 @@ in log buffer."
|
|||
(when remote
|
||||
(magit-insert-unpushed-commits remote branch))))))
|
||||
|
||||
(defun magit-init (dir)
|
||||
"Initialize git repository in specified directory"
|
||||
(interactive (list (read-directory-name "Directory for git repository: ")))
|
||||
(let ((topdir (magit-get-top-dir dir)))
|
||||
(when (or (not topdir)
|
||||
(y-or-n-p
|
||||
(format
|
||||
(if (string-equal topdir (expand-file-name dir))
|
||||
"There is already git repository in %S. Reinitialize?"
|
||||
"There is git repository in %S. Create another in %S?")
|
||||
topdir dir)))
|
||||
(unless (file-directory-p dir)
|
||||
(and (y-or-n-p (format "Directory %S does not exists. Create?" dir))
|
||||
(make-directory dir)))
|
||||
(let ((default-directory dir))
|
||||
(magit-run* (list "git" "init"))))))
|
||||
|
||||
(defun magit-status (dir)
|
||||
(interactive (list (or (and (not current-prefix-arg)
|
||||
(magit-get-top-dir default-directory))
|
||||
(magit-read-top-dir))))
|
||||
(if magit-save-some-buffers
|
||||
(save-some-buffers (eq magit-save-some-buffers 'dontask)))
|
||||
(let* ((topdir (magit-get-top-dir dir))
|
||||
(buf (or (magit-find-buffer 'status topdir)
|
||||
(switch-to-buffer
|
||||
(get-buffer-create
|
||||
(concat "*magit: "
|
||||
(file-name-nondirectory
|
||||
(directory-file-name topdir)) "*"))))))
|
||||
(switch-to-buffer buf)
|
||||
(magit-mode-init topdir 'status #'magit-refresh-status)))
|
||||
(let ((topdir (magit-get-top-dir dir)))
|
||||
(unless topdir
|
||||
(when (y-or-n-p (format "There is no git repository in %S. Create?" dir))
|
||||
(magit-init dir)
|
||||
(setq topdir (magit-get-top-dir dir))))
|
||||
(when topdir
|
||||
(let ((buf (or (magit-find-buffer 'status topdir)
|
||||
(switch-to-buffer
|
||||
(get-buffer-create
|
||||
(concat "*magit: "
|
||||
(file-name-nondirectory
|
||||
(directory-file-name topdir)) "*"))))))
|
||||
(switch-to-buffer buf)
|
||||
(magit-mode-init topdir 'status #'magit-refresh-status)))))
|
||||
|
||||
|
||||
;;; Staging and Unstaging
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue