Skip to content

rse/ase / plugin/skills/ase-repo-import

ase-repo-import

Verified

Import a change set -- a pull/merge request or commit of GitHub, GitLab, or Gitea, given by its URL or by its number `#<number>`, or a diff/patch file -- into the current Git working copy as unstaged and untracked files, merging it with local changes, resolving conflicts semantically, keeping the conflict markers of unresolvable hunks, reporting them as a TODO, and emitting an IMPORTED, CONFLICT, or FAILED verdict. Use when the user calls to "import", "fetch", or "apply" a pull request, merge request, commit, diff, or patch.

@${CLAUDE_SKILL_DIR}/../../meta/ase-control.md @${CLAUDE_SKILL_DIR}/../../meta/ase-skill.md @${CLAUDE_SKILL_DIR}/../../meta/ase-dialog.md @${CLAUDE_SKILL_DIR}/../../meta/ase-getopt.md

$ARGUMENTS

@${CLAUDE_SKILL_DIR}/../../meta/ase-common-resolve.md

Procedure

    1. Set (empty) and (empty). Set to with any leading and trailing whitespace and any surrounding quotes stripped. If is empty, expand the following:

    2. Capture the outputs of the commands git rev-parse --show-toplevel and git rev-parse --absolute-git-dir (taken exactly as given) into and . If a command fails, expand the following:

    3. Run the command git -C "<repo-root/>" ls-files --unmerged. If its output is not empty, expand the following, as the conflicts of the import could not be told apart from the existing ones:

    4. Classify into by the first matching form:

      • #<number/> (only digits after the #): set to request. The form always references the number of the forge and never a task id of ASE. Determine the remotes by running the command git -C "<repo-root/>" remote and set to upstream if it exists, else to origin if it exists. Otherwise, expand the following:

      • A value starting with http:// or https://: remove any ?... and #... suffix and match the remainder as <repo-url/>/<path/>, where is one of:

        • commit/<sha/> or -/commit/<sha/>, or pull/<number/>/commits/<sha/> or pulls/<number/>/commits/<sha/>: set to commit.

        • pull/<number/>, pulls/<number/>, or -/merge_requests/<number/>, optionally followed by .diff, .patch, or /<anything/>: set to request.

        The URL is valid only if matches the regexp ^https?://[A-Za-z0-9.:-]+(/[A-Za-z0-9._~-]+)+$, consists of digits only, and consists of 7 to 64 hexadecimal digits, which keeps it safe for being passed quoted to the git commands. If it is not valid or no form matches, expand the following:

        Determine the remotes by running the command git -C "<repo-root/>" remote -v and set to the first remote whose fetch URL denotes the same host and repository path as (ignoring the scheme, the user, and a trailing .git), so its access credentials are used, or to otherwise.

      • Anything else: set to file and to the absolute path of , resolved against the current working directory. If this is no readable regular file, expand the following:

      1. Capture the default branch of the remote by running the command git -C "<repo-root/>" fetch --quiet --no-tags "<remote/>" HEAD and then the output of the command git -C "<repo-root/>" rev-parse FETCH_HEAD into . If a command fails, expand the following:

      2. Fetch the head by running the command git -C "<repo-root/>" fetch --quiet --no-tags "<remote/>" "<ref/>", with being refs/pull/<number/>/head (GitHub and Gitea) and, if this fails, refs/merge-requests/<number/>/head (GitLab). If both fail, expand the following:

        Capture the output of the command git -C "<repo-root/>" rev-parse FETCH_HEAD into .

      3. Capture the output of the command git -C "<repo-root/>" merge-base "<default-commit/>" "<head-commit/>" into . This is the fork point from the default branch, as the fork point from HEAD would import all foreign commits a lagging HEAD is missing. If the command fails, expand the following:

      Run the command git -C "<repo-root/>" rev-parse --verify --quiet "<sha/>^{commit}". If it fails, the commit has to be fetched first: run the command git -C "<repo-root/>" fetch --quiet --no-tags "<remote/>" "<sha/>" and, if this fails as well (e.g., an abbreviated , which can only be resolved locally), the command git -C "<repo-root/>" fetch --quiet --no-tags "<remote/>" HEAD, and then re-run the verification. Capture its output into and the output of the command git -C "<repo-root/>" rev-parse --verify --quiet "<head-commit/>^" into . If a verification fails, expand the following:

    1. Set /ase-import.patch and . Create the flattened patch by running the command git -C "<repo-root/>" diff --no-color --no-ext-diff --src-prefix=a/ --dst-prefix=b/ --binary --full-index -M --output="<patch/>" "<base-commit/>" "<head-commit/>", which is independent of the diff.* configuration of the user, and set -p1. Capture the output of the command git -C "<repo-root/>" log --oneline "<base-commit/>..<head-commit/>" into . Keep in mind that the fetch made the blobs of the patch available for the 3-way merge.

      Set -p1. Read the header of the patch and set to its commit subjects or descriptive text (or to empty if there is none).

    2. Run the command git -C "<repo-root/>" apply <strip/> --numstat -z "<patch/>". If is file and the command fails or none of the reported paths exists below , while with -p0 instead it succeeds and at least one of the reported paths exists, set -p0 and re-run the command.

      If it still fails (no valid patch) or reports nothing (an empty change set, e.g., of an already merged pull request), expand the following:

    3. Only output the following :

    1. Determine the affected files of the patch: set to the paths reported by the --numstat command above and to those reported more than once (a multi-commit patch). Run the command git -C "<repo-root/>" apply <strip/> --summary "<patch/>" and set to the mapping of the source to the destination path of its rename lines (expanding the compact form dir/{old => new}/file), as --numstat -z reports only the destination. Set to the paths of its create mode lines plus the destinations of its copy lines, and to the paths of its delete mode lines. Do not output anything.

    2. Determine the local changes of the affected files by running the command git -C "<repo-root/>" -c core.quotepath=off status --porcelain=v1 -- <files/>, with being the quoted paths of and the rename sources of . Set to plus every reported path, with a rename source replaced by its destination. These files bypass the 3-way merge below: it either refuses a file with unstaged changes or merges into its staged state, which the final unstaging would lose, and it nests the conflict markers of a file touched more than once.

    3. Apply all other files with a 3-way merge by running the command git -C "<repo-root/>" apply <strip/> --3way --exclude="<file/>" [...] "<patch/>", with one --exclude per file of , and inspect the result. The command is atomic:

      • If it succeeded or reported U <file/> lines (conflict markers written), continue with the next item.

      • Otherwise nothing was applied: add every file of an error: <file/>: <reason/> line to , with a rename source replaced by its destination, and re-run the command. If no line names a further file, expand the following:

    4. Set to the paths of and the rename sources of , without the files of and their rename sources. Only these got staged by the command above. Do not output anything.

      1. Apply the hunks of the excluded files directly onto the working directory, leaving their staged state alone, by running the command git -C "<repo-root/>" apply <strip/> --reject --include="<file/>" [...] "<patch/>", with one --include per file of . Applicable hunks are applied, also on top of local changes, and the others are rejected.

      2. Turn every rejected hunk into a conflict in the file, as no base of the 3-way merge exists for it: take the hunks from <file/>.rej, but for a file of from the rejected sections of the patch, as <file/>.rej holds only the rejects of the last section. Locate the region of the hunk in the current file via its removed and context lines and replace this region by the following, with the labels of a 3-way merge, which you MUST write via Edit without changing anything else of the file:

        <<<<<<< ours
        [lines of the current region]
        ||||||| base
        [removed and context lines of the hunk]
        =======
        [added and context lines of the hunk]
        >>>>>>> theirs
        

        Afterwards, remove <file/>.rej. If the region of a hunk cannot be located, keep the hunk in <file/>.rej, so it gets escalated below.

      3. Handle every file which was reported by an error: <file/>: <reason/> line without any rejected hunk:

        • A new file colliding with an existing one (already exists in working directory): if the existing content equals the content of the patch, nothing has to be done. For different text content, write the existing content and the content of the patch as one conflict spanning the entire file, without a base section.

        • Everything else (e.g., a missing file, the removal of a locally changed file, a binary patch): leave the file untouched and record it in with its conflict kind, a one-line intent of each side, and a one-line reason.

    5. Only output the following :

    1. Set to the paths of , the rename sources of , and all existing <file/>.rej of them. Do not output anything.

    2. Resolve the conflicts by expanding the following, where ours are HEAD and the local changes and theirs is the imported change set with the intent :

    1. Set to one to three sentences stating what the change set does, derived from the actual changes in (for a large patch, at least from its significant hunks) and not only from the claims of . For every path of , which is relative to , set to added if it is in , removed if it is in , renamed if it is a destination of , or modified otherwise, followed by , not applied if left the file untouched. Set to the path, for renamed prefixed with its rename source and →, and to a short phrase stating what the patch changes in this file. Do not output anything.

    2. If is not empty, remove it by running the command rm -rf "<fetched-patch/>". Do not output anything.

    3. Only output the following , with one table row per path of , grouped in the order added, modified, renamed, and removed:

      ChangeFileSummary
      <file/>
      [...][...][...]
    4. Set to plus . Set IMPORTED if is empty, or CONFLICT otherwise. Do not output anything.

    5. <file/>:<lines/> (): ◦ ours: ◦ theirs: [...]

    6. Only output the following :

    7. Give the closing hint by expanding the following (which, depending on the configured , may expand into nothing and hence emit no output at all):

receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall