gpt4 book ai didi

Emacs/Magit -- 如何在 Github 上创建和删除存储库

转载 作者:行者123 更新时间:2023-12-01 23:57:08 26 4
gpt4 key购买 nike

我在 Magit 的第 5 步和第 7 步创建新存储库时遇到问题。如果它们存在,那么第 5 步和第 7 步的交互功能等价物是什么(请)?

如果没有交互式等效项,我想我将需要编写自己的 shell 命令函数——当然,除非有人想先尝试一下。 :)


创建 -- 命令行配方

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"}'


删除 -- 命令行配方

注意:用户 token 必须具有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
"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-processcurl,或者使用包装 Github API 的 gh.el。

要添加新 Remote ,请在 Magit 状态缓冲区中键入 M a

关于Emacs/Magit -- 如何在 Github 上创建和删除存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23039562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com