Skip to content

fix(git): don't suggest '(no branch, rebasing ...)' as a branch - #2676

Open
ump45nose wants to merge 1 commit into
withfig:masterfrom
ump45nose:fix-git-no-branch-rebasing
Open

ump45nose wants to merge 1 commit into
withfig:masterfrom
ump45nose:fix-git-no-branch-rebasing

Conversation

@ump45nose

Copy link
Copy Markdown

While a rebase is in progress, git branch reports the current line as * (no branch, rebasing <branch>). The branch post-processing treated that as the current branch, so git reset (and other branch-completing commands) suggested the literal string (no branch, rebasing main) as a branch name.

Changes

  • src/git.ts: postProcessBranches now drops the * line when it reports (no branch...) — same handling as the existing HEAD detached case — so no bogus current-branch suggestion is produced during a rebase. Other real branches are still suggested.

Closes #2463

Validation

  • Behavior verified against the branch-listing transcript reported in the issue (* (no branch, rebasing main) + normal branches): the bogus entry is filtered, remaining branches kept.
  • prettier --check and eslint clean; tsc --noEmit reports no diagnostics for git.ts.

@withfig-bot

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@withfig-bot

Copy link
Copy Markdown
Contributor

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<Record<string, string>>((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
Copy Markdown
Contributor

Hello @ump45nose,
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.

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.

[git] Bad branch name completion when rebasing

2 participants