stash_save
Save uncommitted changes to a Git stash with a custom message. Optionally include untracked files, preserve staged changes, or add ignored files for flexible repository management.
Instructions
Save changes to stash
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| all | No | Include ignored files | |
| includeUntracked | No | Include untracked files | |
| keepIndex | No | Keep staged changes | |
| message | No | Stash message | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Implementation Reference
- src/git-operations.ts:721-760 (handler)The core handler function that constructs and executes the 'git stash' command with appropriate flags based on the provided StashOptions.static async stashSave({ path, message, includeUntracked, keepIndex, all }: StashOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); let command = 'stash'; if (typeof message === 'string' && message.length > 0) { command += ` save "${message}"`; } if (includeUntracked) { command += ' --include-untracked'; } if (keepIndex) { command += ' --keep-index'; } if (all) { command += ' --all'; } const result = await CommandExecutor.executeGitCommand( command, context.operation, repoPath ); return { content: [{ type: 'text', text: `Changes stashed successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'stash_save', invalidateCache: true, // Invalidate stash and status caches stateType: RepoStateType.STASH } ); }
- src/tool-handler.ts:437-469 (registration)Registers the 'stash_save' tool with the MCP server, including its description and input schema definition.{ name: 'stash_save', description: 'Save changes to stash', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, message: { type: 'string', description: 'Stash message', }, includeUntracked: { type: 'boolean', description: 'Include untracked files', default: false }, keepIndex: { type: 'boolean', description: 'Keep staged changes', default: false }, all: { type: 'boolean', description: 'Include ignored files', default: false } }, required: [], }, },
- src/types.ts:101-107 (schema)TypeScript interface defining the shape of parameters accepted by the stash_save tool.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 used to validate input arguments conform to StashOptions before dispatching to handler.export function isStashOptions(obj: any): obj is StashOptions { return obj && validatePath(obj.path); }
- src/tool-handler.ts:658-661 (handler)Dispatch handler in the main tool executor switch statement that validates arguments and calls the GitOperations.stashSave implementation.case 'stash_save': { const validArgs = this.validateArguments(operation, args, isStashOptions); return await GitOperations.stashSave(validArgs, context); }