Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to clone branches #2895

Closed
szmarczak opened this issue Mar 15, 2020 · 25 comments · Fixed by #2896
Closed

Add a button to clone branches #2895

szmarczak opened this issue Mar 15, 2020 · 25 comments · Fixed by #2896

Comments

@szmarczak
Copy link

To clone a branch manually:

  1. Go to the branch you want to clone.
  2. Click Edit on any file. Do not make any changes.
  3. Make sure you have selected this:

image

  1. Open Chrome Dev Tools.
  2. Inspect the Propose file change button.
  3. Remove the disabled attribute.
  4. Click Propose file change.

🎉 In other words, it makes a spin off from your branch and makes an empty commit (I don't know of any solution that wouldn't create an empty commit).

@yakov116
Copy link
Member

Only way it through v3 api
https://gist.github.com/potherca/3964930

@fregante
Copy link
Member

You can already clone it:

  1. Visit branch
  2. Open branch selector
  3. Type new branch name
  4. Click create

@yakov116
Copy link
Member

@fregante wow I never knew that!!

@fregante
Copy link
Member

fregante commented Mar 15, 2020

If this “Duplicate” button is added to the Branches page, it can replace this feature request: #2500, also because renaming isn’t a safe operation

@yakov116
Copy link
Member

@fregante curious why is renaming not a safe option?

@fregante
Copy link
Member

fregante commented Mar 15, 2020

Explained in #2500: it doesn’t move PRs

@yakov116
Copy link
Member

query GetBranchInfo {
  repository(owner: "yakov116", name: "TestR") {
    id
    ref(qualifiedName: "Test") {
      target {
        oid
      }
    }
  }
}

mutation CreateBrach {
  createRef(input: {repositoryId: "MDEwOlJlcG9zaXRvcnkyNDQyMTU0NzY=", oid: "a1a98b7b5460f87a31cc6e12699a6e71e2390988", name: "refs/head/yes"}) {
    clientMutationId
    ref {
      id
    }
  }
}

@fregante like this? Or do you want to hack the drop down menu?

@fregante
Copy link
Member

If v3 only requires a fetch we can use that instead of v4, we don't get about its body anyway

@fregante
Copy link
Member

fregante commented Mar 15, 2020

On https://github.com/sindresorhus/refined-github/branches

  1. Add icon-only button next to each delete button
  2. On click, ask name via prompt ("cancel" or empty name will cancel the action)
  3. Change the icon to "Creating..."
  4. await api.v3(...)
  5. Update UI (I think just location.reload())

@yakov116
Copy link
Member

yakov116 commented Mar 15, 2020

If v3 only requires a fetch we can use that instead of v4, we don't get about its body anyway

They both require 2 calls. One to get the commit the brach is up to. And one to create the branch.

Creating the branch via V3 is simple.

@fregante
Copy link
Member

fregante commented Mar 15, 2020

Ugh. The GraphQL schema for this is awful. Private IDs should not be exposed at all.

Two v3 calls are fine since it's a specific user action.

This is not exactly a high-priority feature though.

@yakov116
Copy link
Member

yakov116 commented Mar 15, 2020

await api.v3(repos/${user}/${repo}/git/refs/heads);
Gives all the branches
Only make the call after the user clicks?
The benefit of using v3 for the branches is that we get all of them at once
To create is
POST /repos/:owner/:repo/git/refs
OR
use V4 and only get that branch info, then use v3 to create the branch

@fregante
Copy link
Member

The last OR sounds good. V4 GET, V3 POST

@yakov116
Copy link
Member

V3 I can get the direct info

@fregante
Copy link
Member

What’s direct info? V4 also has the commit info, it’s just what we need. V4 requests are light, v3 GET requests aren’t

@yakov116
Copy link
Member

await api.v3(repos/${user}/${repo}/git/refs/heads/${branchName!});

@yakov116
Copy link
Member

I have every thing done I am having a hard time making a post

@fregante
Copy link
Member

Only make the call after the user clicks?

Why do you keep asking this? I said it before. Is this going to be like your last PR of me saying the same thing 4 different ways before the code was updated?

@yakov116
Copy link
Member

yakov116 commented Mar 15, 2020

No no. I know I know. Your right.

It was a mistake that line got in there

@fregante
Copy link
Member

@szmarczak why do you need to clone a branch?

@yakov116
Copy link
Member

Owh... I thought you closed the issue

image

@szmarczak
Copy link
Author

Sometimes I need to rebase a PR I'm working on (e.g. start from scratch with a different implementation) and I don't want to lose the current progress.

@fregante
Copy link
Member

Commits aren't lost, you just need to save the commit hash

@szmarczak
Copy link
Author

IKR, but I'm lazy to do so :(

@szmarczak
Copy link
Author

I think that the clone-branch feature would be a safer option :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants