Emacs / Magit - 如何在Github上创建和删除存储库 [英] Emacs / Magit -- how to create and delete repositories on Github

查看:170
本文介绍了Emacs / Magit - 如何在Github上创建和删除存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Magit中遇到麻烦,步骤5和步骤7创建一个新的存储库。如果存在,第5步和第7步的交互功能等效(请)是什么?

I am having trouble in Magit with step number 5 and step number 7 to create a new repository. If they exist, what are the interactive function equivalents (please) for steps 5 and 7?

如果没有交互式的等价物,我想我将需要自己写shell命令功能 - 除非当然有人想先攻击他们。 :)

If there are no interactive equivalents, I guess I will need to write my own shell command functions -- unless, of course, someone would like to take a stab at them first. :)

CREATE - COMMAND-LINE RECIPE

CREATE -- COMMAND-LINE RECIPE

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 git@github.com: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}'

NOTE: Steps 5 and 6 can be combined (if desired) as follows: curl -u 'USERNAME':'PASSWORD' https://api.github.com/user/repos -d '{"name":"REPO-NAME"}'

删除 - COMMAND-LINE RECIPE

DELETE -- COMMAND-LINE RECIPE

注意:用户令牌必须 delete_repo 权限。请参阅 delete-remote-repo 的文档字符串。

NOTE:  The user token must have delete_repo authority. See doc-string of delete-remote-repo.

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






EDIT (2014年4月13日):第一份工作草案。


EDIT (April 13, 2014):  First working draft.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
                            "git@github.com:"
                            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!") )))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


推荐答案

Magit不提供任何与Githhb交互的命令,您需要在 call-process curl 之间编写自己的命令,或者使用包含Github API的gh.el。

Magit does not provide any commands to interact with Githhb. You'll need to write your own command, around call-process and curl, or with gh.el which wraps the Github API.

要添加新的远程,请键入 M a Magit状态缓冲区。

To add a new remote, type M a in the Magit status buffer.

这篇关于Emacs / Magit - 如何在Github上创建和删除存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆