Refined-github: Add a button to clone branches

Created on 15 Mar 2020  Â·  25Comments  Â·  Source: sindresorhus/refined-github

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.

:tada: 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).

enhancement under discussion

Most helpful comment

Explained in #2500: it doesn’t move PRs

All 25 comments

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

You can already clone it:

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

@fregante wow I never knew that!!

If this “Duplicate” button is added to the Branches page, it can replace this feature request: https://github.com/sindresorhus/refined-github/issues/2500, also because renaming isn’t a safe operation

@fregante curious why is renaming not a safe option?

Explained in #2500: it doesn’t move PRs

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?

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

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())

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.

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.

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

The last OR sounds good. V4 GET, V3 POST

V3 I can get the direct info

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

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

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

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?

No no. I know I know. Your right.

It was a mistake that line got in there

@szmarczak why do you need to clone a branch?

Owh... I thought you closed the issue

image

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shivapoudel picture shivapoudel  Â·  3Comments

hkdobrev picture hkdobrev  Â·  3Comments

olso picture olso  Â·  3Comments

Arcanemagus picture Arcanemagus  Â·  3Comments

yakov116 picture yakov116  Â·  3Comments