From 9db7719b9640e7ee48759f2a639c836e7c401ccd Mon Sep 17 00:00:00 2001 From: Alexey Voinov Date: Wed, 4 Feb 2009 17:49:10 +0300 Subject: [PATCH] Support for git init --- magit.el | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/magit.el b/magit.el index aa2c8ac8..905b70a8 100644 --- a/magit.el +++ b/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