stash_pop
Apply and remove a Git stash from a specified repository path using the stash index. Part of the Git MCP Server, enabling enhanced Git operations for efficient repository management.
Instructions
Apply and remove a stash
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | No | Stash index | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Implementation Reference
- src/git-operations.ts:762-788 (handler)The primary handler function that executes the 'git stash pop' command, validates the repository, handles caching invalidation, and formats the response.static async stashPop({ path, index = 0 }: StashOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); const result = await CommandExecutor.executeGitCommand( `stash pop stash@{${index}}`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Stash applied successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'stash_pop', invalidateCache: true, // Invalidate stash and status caches stateType: RepoStateType.STASH } ); }
- src/tool-handler.ts:470-488 (schema)The input schema definition for the stash_pop tool, registered in the ListTools handler, defining parameters path and index.{ name: 'stash_pop', description: 'Apply and remove a stash', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, index: { type: 'number', description: 'Stash index', default: 0, }, }, required: [], }, },
- src/tool-handler.ts:663-666 (registration)The switch case in the CallToolRequest handler that validates arguments using isStashOptions and dispatches to GitOperations.stashPop.case 'stash_pop': { const validArgs = this.validateArguments(operation, args, isStashOptions); return await GitOperations.stashPop(validArgs, context); }
- src/types.ts:101-107 (schema)TypeScript interface StashOptions defining the input parameters for stash operations, used for type checking and validation.export interface StashOptions extends GitOptions, BasePathOptions { message?: string; index?: number; includeUntracked?: boolean; // Include untracked files keepIndex?: boolean; // Keep staged changes all?: boolean; // Include ignored files }
- src/types.ts:194-196 (schema)Type guard function isStashOptions used to validate input arguments before calling the handler.export function isStashOptions(obj: any): obj is StashOptions { return obj && validatePath(obj.path); }