Create new repo?
jdtsmith opened this issue · comments
Is your feature request related to a problem? Please describe.
I often start playing around with some code, then decide I should create a repo for it. I've not found a way to do this with forge.
Describe the solution you'd like
A command that prompts for a repo name, then creates a new one in the default directory of the current buffer, then clones it locally into the default directory.
Describe alternatives you've considered
Now I create one on GH, then with magit, create a repo locally, add the former as a remote, sync, and switch branches.
@jdtsmith This is indeed possible and relatively easy to implement, but I am not sure what is missing from the command-line tool that makes it necessary to implement this specifically in consult-gh. You can simply open a terminal (inside or outside emacs) and use the gh
command to achieve what you want by passing arguments like this gh repo create --source . --push --private
. Note that you need to specify --private
or --public or --internal
otherwise you will get an error. You can also run gh repo create
without any arguments, and gh
will walk you through the process by asking you questions in the command-line.
You can simply make an alias for the above, if you always want the same thing. Or you can create an elisp function like the examples below using what is already available in consult-gh for your use-case:
For what you describe with just "repo name" as a variable:
(defun consult-gh-create-repo (name)
(interactive "sRepo Name:")
(consult-gh--call-process "repo" "create" (format "%s" name) "--private" "--source" default-directory "--push")
)
or, if you want more options, you can use let bindings and query the user for more options:
(defun consult-gh-create-repo (&optional directory name visibility push)
(interactive)
(let* ((directory (expand-file-name (read-directory-name "Select Directory:")))
(name (or name (read-string "Repo Name:" (file-name-nondirectory (string-trim directory nil "/")))))
(visibility (format "--%s" (completing-read "What should be the visibilty of the repo?" '("public" "private" "internal"))))
(push (if (yes-or-no-p "Should the local repo be pushed to remote?") "--push" nil))
(output (consult-gh--call-process"repo" "create" name "--private" "--source" directory push))
)
(message (cadr output))
))
Note how I am saving consult-gh--command-to-string
to output and messaging it to capture possible errors and issues, but if you don't need that, you can just run the (consult-gh--...) line in the let function.
I think this addresses what you need. Of course, this does not take care of creating git repositories, etc. That you still have to do manually by running git init
and then stage and commit, etc. or use magit or some other packages inside emacs. The alternative would be to create an empty repo without specifying source, and then use consult-gh
to clone the empty repo locally and then copy your files into the new directory and push back to remote.
Now, I can of course simply add this as another interactive command to the repo, but I am not yet convinced that we should provide this kind of scripts in consult-gh by default because it is specific to individual workflows and relatively easy to make by each user. We can perhaps create a wiki to capture this kind of ideas and useful scripts, but I'd rather leave it to individual users to implement them rather than trying to provide a solution for every individual case as part of consult-gh by default and make it a bloated package. @jdtsmith Let me know if this addresses your need and if there is any clear advantage of doing this in consult-gh (e.g. better user experience, or ...) as a default interactive function, then I'm all ears, and we can figure out how to implement it as a more general solution too, but all you need is something like functions above, then you can simply add it to your init file. What do you think?
Looks like a good option, thanks. I'll look into it.
I'm closing this issue since there is no new activity. Feel free to reopen if needed.
@jdtsmith Just FYI ended up implementing this in the develop branch now because I'm trying to integrate consult-gh with some other packages like consult-omni to allow making new projects without opening terminal.