Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add an option for custom contents of file. #6

Open
gucong3000 opened this issue Jun 13, 2017 · 10 comments
Open

How to add an option for custom contents of file. #6

gucong3000 opened this issue Jun 13, 2017 · 10 comments

Comments

@gucong3000
Copy link

gucong3000 commented Jun 13, 2017

I'm planning to use ' git-blame' instead of my js file, but I need to customize contents of file.

@gucong3000 gucong3000 changed the title How to add an option for custom stdin to the spawned process How to add an option for custom contents of file. Jun 13, 2017
@gucong3000
Copy link
Author

gucong3000 commented Jun 13, 2017

This is an example used in gulp:

var toReadStream = require('spawn-to-readstream'),
    spawn        = require('child_process').spawn;

/**
 * Get what revision and author last modified each line of a file
 * @param   {vinyl}    file    `vinyl` file (https://github.com/gulpjs/vinyl)
 */
function blame (file) {
  var args = ['blame', '-l', '-t', '-w', '-C', '-M'];
  if (file.contents) {
    args.push('--contents');
    args.push('-');
  }
  args.push('--');
  args.push(file.path);

  var blame = spawn('git', args, {
    cwd: file.cwd
  });

  if (file.isBuffer()) {
    blame.stdin.write(file.contents);
    blame.stdin.end();
  } else if (file.isStream()) {
    file.contents.pipe(blame.stdin);
  }

  return toReadStream(blame);
}

@alessioalex
Copy link
Owner

Hi @gucong3000 , not sure I understand. This module parses the output of the git blame command, what exactly do you mean by custom contents of file?

As for getting the corrects results after modifying a document (the issue opened in vscode-gitblame repo), I think you need to keep track of git blame data and see what's changed in there.

@gucong3000
Copy link
Author

blame

In this animation, the last line of code is not modified, but the blame is lost because of the newline that was inserted earlier

@alessioalex
Copy link
Owner

I see. This should be handled in vscode-gitblame though, it's not an issue of git-blame though.

@gucong3000
Copy link
Author

git-blame should provide a parameter to vscode-gitblame to pass the unsaved code

@alessioalex
Copy link
Owner

That's outside of the scope of this module in my opinion. vscode-gitblame should keep track of the edited lines instead.

@gucong3000
Copy link
Author

Only need a little change, can I push a PR to demonstrate my intention?

@alessioalex
Copy link
Owner

Ok

@gucong3000
Copy link
Author

@alessioalex
Copy link
Owner

I understand. Thank you for the pull requests. I'll take a look over them when I have some time. Also, please leave the linting as it is and don't add standard or other stuff. Those can be addressed in other pull requests.

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

No branches or pull requests

2 participants