Skip to content

Commit

Permalink
Enhances copy/apply/paste patch-related commands
Browse files Browse the repository at this point in the history
 - Add new "Paste Copied Changes (Patch)" command for discovery
 - Renames commands for clarity
 - Ensure patch contents always end with a newline (since its required)
  • Loading branch information
eamodio committed Aug 9, 2024
1 parent 5af7853 commit b9621db
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5651,12 +5651,17 @@
},
{
"command": "gitlens.applyPatchFromClipboard",
"title": "Apply Copied Patch",
"title": "Apply Copied Changes (Patch)",
"category": "GitLens"
},
{
"command": "gitlens.pastePatchFromClipboard",
"title": "Paste Copied Changes (Patch)",
"category": "GitLens"
},
{
"command": "gitlens.copyPatchToClipboard",
"title": "Copy as Patch",
"title": "Copy Changes (Patch)",
"category": "GitLens"
},
{
Expand Down Expand Up @@ -9762,6 +9767,10 @@
"command": "gitlens.applyPatchFromClipboard",
"when": "gitlens:enabled && !gitlens:untrusted && !gitlens:hasVirtualFolders"
},
{
"command": "gitlens.pastePatchFromClipboard",
"when": "gitlens:enabled && !gitlens:untrusted && !gitlens:hasVirtualFolders"
},
{
"command": "gitlens.copyPatchToClipboard",
"when": "gitlens:enabled && !gitlens:untrusted && !gitlens:hasVirtualFolders"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class CopyPatchToClipboardCommand extends CreatePatchCommandBase {
@command()
export class ApplyPatchFromClipboardCommand extends Command {
constructor(private readonly container: Container) {
super(Commands.ApplyPatchFromClipboard);
super([Commands.ApplyPatchFromClipboard, Commands.PastePatchFromClipboard]);
}

async execute() {
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const enum Commands {
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
CopyRelativePathToClipboard = 'gitlens.copyRelativePathToClipboard',
ApplyPatchFromClipboard = 'gitlens.applyPatchFromClipboard',
PastePatchFromClipboard = 'gitlens.pastePatchFromClipboard',
CopyPatchToClipboard = 'gitlens.copyPatchToClipboard',
CopyWorkingChangesToWorktree = 'gitlens.copyWorkingChangesToWorktree',
CreatePatch = 'gitlens.createPatch',
Expand Down
4 changes: 4 additions & 0 deletions src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
): Promise<GitCommit | undefined> {
const scope = getLogScope();

if (!contents.endsWith('\n')) {
contents += '\n';
}

// Create a temporary index file
const tempDir = await fs.mkdtemp(path.join(tmpdir(), 'gl-'));
const tempIndex = joinPaths(tempDir, 'index');
Expand Down

0 comments on commit b9621db

Please sign in to comment.