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

fix(git): Separate local and remote branches in branch display #2412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

do-not-do-that
Copy link

Bug Cause

When retrieving the branch list, both local and remote branches are fetched and exposed with the same names.
As a result, when users use the autocomplete feature, they see suggestions for branches that have been deleted locally (or remotely).
#2101 #2268

Additional Features

  • If both local and remote branches exist, display as before (description: Branch).
  • If only a local branch exists, add "Local branch" to the description.
  • If only a remote branch exists, set name to remotes/origin/{branch}, use an alert icon, set description to "Remote branch", and lower the priority.

Scenario

image
  • local & remote : main, develop
  • local only : localBranch
  • remote only : remoteBranch

AS-IS

image image image

TO-BE

image image image

There could be multiple solutions, such as showing only local branches. Please provide suggestions, and I will make adjustments accordingly.

@withfig-bot
Copy link
Collaborator

withfig-bot commented Jul 21, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@withfig-bot
Copy link
Collaborator

Overview

src/git.ts:

Info:

Single Functions:

postProcess:

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((line) => {
        return {
          name: line.substring(0, 7),
          icon: "fig://icon?type=node",
          description: line.substring(7),
        };
      });
    }

postProcess:

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((line) => {
        return {
          name: line.substring(0, 7),
          icon: "fig://icon?type=node",
          description: line.substring(7),
        };
      });
    }

postProcess:

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((file) => {
        return {
          // account for conventional commit messages
          name: file.split(":").slice(2).join(":"),
          insertValue: file.split(":")[0],
          icon: `fig://icon?type=node`,
        };
      });
    }

postProcess:

 function (out, tokens) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((file) => {
        return {
          name: file,
          insertValue: (!tokens.includes("--") ? "-- " : "") + file,
          icon: `fig://icon?type=file`,
          description: "Staged file",
        };
      });
    }

postProcess:

 function (out) {
      const remoteURLs = out.split("\n").reduce((dict, line) => {
        const pair = line.split("\t");
        const remote = pair[0];
        const url = pair[1].split(" ")[0];

        dict[remote] = url;
        return dict;
      }, {});

      return Object.keys(remoteURLs).map((remote) => {
        const url = remoteURLs[remote];
        let icon = "box";
        if (url.includes("github.com")) {
          icon = "github";
        }

        if (url.includes("gitlab.com")) {
          icon = "gitlab";
        }

        if (url.includes("heroku.com")) {
          icon = "heroku";
        }
        return {
          name: remote,
          icon: `fig://icon?type=${icon}`,
          description: "Remote",
        };
      });
    }

postProcess:

 function (output) {
      return output.split("\n").map((tag) => ({
        name: tag,
        icon: "🏷️",
      }));
    }

script:

 function (context) {
      if (context.includes("--staged") || context.includes("--cached")) {
        return [
          "bash",
          "-c",
          `git --no-optional-locks status --short | sed -ne '/^M /p' -e '/A /p'`,
        ];
      } else {
        return [
          "bash",
          "-c",
          `git --no-optional-locks status --short | sed -ne '/M /p' -e '/A /p'`,
        ];
      }
    }

URLs:

  • http://developercertificate.org
  • http://developercertificate.org

@withfig-bot
Copy link
Collaborator

Hello @do-not-do-that,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments include the args property (args: {})?
  • Are all options modular? E.g. -a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

@do-not-do-that do-not-do-that changed the title fix(git): Separate local and remote branches in branch display#2101 fix(git): Separate local and remote branches in branch display Jul 21, 2024
@do-not-do-that
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

withfig-bot added a commit that referenced this pull request Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants