2014-04-13 99 views
3

我在第5步和第7步創建新的存儲庫時遇到了麻煩。如果它們存在,那麼步驟5和步驟7的交互功能是否等同於(請)?Emacs/Magit - 如何在Github上創建和刪除存儲庫

如果沒有交互式等價物,我想我需要編寫我自己的shell命令函數 - 除非有人想先嚐試一下它們。 :)


CREATE - 命令行菜譜

1. $ touch README.md 

2. $ /usr/local/git/bin/git init 

3. $ /usr/local/git/bin/git add . 

4. $ /usr/local/git/bin/git commit -m "First commit." 

5. $ curl -u 'USERNAME' https://api.github.com/user/repos -d '{"name":"REPO-NAME"}' 

6. $ Enter password: PASSWORD 

7. $ /usr/local/git/bin/git remote add origin [email protected]:USERNAME/REPO-NAME.git 

8. $ /usr/local/git/bin/git push origin master 

:步驟5和6可被組合(如果需要的話)如下:curl -u 'USERNAME':'PASSWORD' https://api.github.com/user/repos -d '{"name":"REPO-NAME"}'


DELETE - COMMAND-LINE RECIPE

注意:用戶令牌必須delete_repo權限。請參閱delete-remote-repo的文檔字符串。

curl -X DELETE -H 'Authorization: token xxx' https://api.github.com/repos/USERNAME/REPO-NAME 

編輯(2014年4月13日):第一個工作草案。

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;; http://stackoverflow.com/q/23039562/2112489 

(defvar git-username nil 
"The username of the Github account.") 
(make-variable-buffer-local 'git-username) 

(defvar git-password nil 
"The password of the Github account.") 
(make-variable-buffer-local 'git-password) 

(defvar git-token nil 
"The applicable token of the Github account.") 
(make-variable-buffer-local 'git-token) 

(defvar repo-name nil 
"The name of the Github repository.") 
(make-variable-buffer-local 'repo-name) 

(defun create-remote-repo() 
"Execute this function from the root directory of the repo -- e.g., in dired-mode." 
(interactive) 
    (setq git-username (read-string "Name of User: ")) 
    (setq git-password (read-string "Password of User: ")) 
    (setq repo-name (read-string "Name of Repository: ")) 
    (set-process-sentinel 
    (start-process 
     "repo-process" 
     "*REPO*" 
     "/usr/bin/touch" 
     "README.md") 
    (lambda (p e) (when (= 0 (process-exit-status p)) 
     (set-process-sentinel 
     (start-process 
      "repo-process" 
      "*REPO*" 
      "/usr/local/git/bin/git" 
      "init") 
     (lambda (p e) (when (= 0 (process-exit-status p)) 
      (set-process-sentinel 
      (start-process 
       "repo-process" 
       "*REPO*" 
       "/usr/local/git/bin/git" 
       "add" 
       ".") 
      (lambda (p e) (when (= 0 (process-exit-status p)) 
       (set-process-sentinel 
       (start-process 
        "repo-process" 
        "*REPO*" 
        "/usr/local/git/bin/git" 
        "commit" 
        "-m" 
        "\"First commit.\"") 
       (lambda (p e) (when (= 0 (process-exit-status p)) 
        (set-process-sentinel 
        (start-process 
         "repo-process" 
         "*REPO*" 
         "/usr/bin/curl" 
         "-u" 
         (concat 
         git-username 
         ":" 
         git-password) 
         "https://api.github.com/user/repos" 
         "-d" 
         (concat 
         "\{\"name\":\"" 
         repo-name 
         "\"\}")) 
        (lambda (p e) (when (= 0 (process-exit-status p)) 
         (set-process-sentinel 
         (start-process 
          "repo-process" 
          "*REPO*" 
          "/usr/local/git/bin/git" 
          "remote" 
          "add" 
          "origin" 
          (concat 
          "[email protected]:" 
          git-username 
          "/" 
          repo-name 
          ".git")) 
         (lambda (p e) (when (= 0 (process-exit-status p)) 
          (set-process-sentinel 
          (start-process 
           "repo-process" 
           "*REPO*" 
           "/usr/local/git/bin/git" 
           "push" 
           "origin" 
           "master") 
          (lambda (p e) (when (= 0 (process-exit-status p)) 
           (if (eq major-mode 'dired-mode) 
           (revert-buffer)) 
           (display-buffer (get-buffer "*REPO*") nil) 
           (message 
           "Repository `%s` has been successfully created!" 
           repo-name))))))))))))))))))))))) 

(defun delete-remote-repo() 
"To delete a repository, the user must have token `delete_repo` authorization. 
Visit your `Account Settings` | `Applications`. Either edit a current token 
or generate a new token with `delete_repo` authorization, and write down the 
token in a safe place because it is only displayed one time." 
(interactive) 
    (setq git-username (read-string "Name of User: ")) 
    (setq repo-name (read-string "Name of Repository: ")) 
    (setq git-token (read-string "Token (with `delete_repo` authority): ")) 
    (set-process-sentinel 
    (start-process "delete-repo-process" "*DELETE-REPO*" 
     "/usr/bin/curl" 
     "-X" 
     "DELETE" 
     "-H" 
     (concat 
     "Authorization: token " 
     git-token 
     ) 
     (concat 
     "https://api.github.com/repos/" 
     git-username 
     "/" 
     repo-name)) 
    (lambda (p e) (when (= 0 (process-exit-status p)) 
     (display-buffer (get-buffer "*DELETE-REPO*") nil) 
     (if (with-current-buffer (get-buffer "*DELETE-REPO*") 
       (equal (buffer-size) 0)) 
      (progn 
      (with-current-buffer (get-buffer "*DELETE-REPO*") 
       (insert "It looks like everything worked okay.")) 
      (message "Repository `%s` has been successfully deleted!" repo-name)) 
      (message "OOOPS!!! Something went wrong in the deletion process!")))))) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
+0

不錯,但我的抱怨在於git(程序和協議)比github(網站)更普遍。魔術模式支持前者;將其應用於後者是方便的,但有些限制。 –

回答

3

Magit不提供任何命令與Githhb進行交互。您需要編寫自己的命令,大約在call-processcurl之間,或者使用封裝了Github API的gh.el。

要添加新的遠程,請在Magit狀態緩衝區中鍵入M a

+0

謝謝 - 我已經編寫了一個名爲'create-repo'的函數,它可以從'dired-mode'中的選定的根目錄庫目錄中運行 - 新函數作爲我的最初問題的編輯發佈。 – lawlist

+0

@lawlist你應該真的考慮重構......並且可能使用VC而不是對Git進行脫殼。除了創建Github repo之外,Emacs可以從vc.el中完成* all *。 – lunaryorn

相關問題