Skip to content

[Enhancement] Custom Action on Branch needs to know more about Remote (when applicable) #1666

@goran-w

Description

@goran-w

When running a Custom Action on the Branch scope, the ${BRANCH} variable contains the (short / abbreviated) name of the branch, but there's currently no (easy) way for the Action to distinguish whether the branch is a local or a remote one (and in the latter case, what the name of the Remote is). This information can be crucial for correct processing, for example when an Action needs to communicate (push etc) with a remote service like GitHub.

For a remote branch, its (abbreviated) name starts with the Remote name: <remote>/<branch> (for example: origin/my-branch) However, there's nothing preventing a user from creating a local branch with a completely identical name, or any other name which has a <ref-folder>/<ref-file> structure. Therefore, without additional info we can't assume that the "top-folder-part" of the name is a Remote (rather than just any other ref-folder).

While it's possible to use Git commands and additional string-parsing to extract the remote name (after extracting the full ref name), a much more user-friendly solution would be to strip the Remote prefix from the ${BRANCH} variable and instead expose it in a separate variable ${BRANCH_REMOTE} (or similar) which would be an empty string for a local branch. From a user standpoint, it's much easier to re-assemble the <remote>/<branch> name (if needed) than to extract the needed info from the (abbreviated) branch-name alone.

Separating the Branch and Remote names into separate variables is IMHO the most user-friendly solution, but other (less attractive) alternatives exist:

  • Adding a new variable ${FULL_REF} (or similar), containing the full (non-abbreviated) ref-name for the Branch and Tag scopes (as returned by git rev-parse --symbolic-full-name <abbreviated-ref-name>).
  • Separating Local Branch and Remote Branch into two separate Action Scopes.
  • Adding a new variable ${BRANCH_IS_REMOTE}.
  • Do nothing, leaving the user to figure out an alternative solution for themselves.

These latter alternatives are IMHO not good solutions on their own.

However, the ${FULL_REF} idea would be useful in addition to the ${BRANCH_REMOTE} solution for remote branches...

(Also, separating the Local / Remote branch-scopes would make it easier to make Actions apply to only one of the scopes, but might necessitate a 3rd "combined" Local + Remote branch-scope to avoid having to duplicate Actions that apply to both...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions