rkotze / git-mob

Co-author commits tool. A cross-platform command-line tool for social coding. Includes co-authors in commits when pair/mob programming.
https://www.npmjs.com/package/git-mob
MIT License
182 stars 21 forks source link

Allow per repo `<repo>/.git-coauthors` file #107

Closed tlabeeuw closed 1 year ago

tlabeeuw commented 1 year ago

Summary

Instead of only having a global ~/.git-coauthors file, I would like to have a per repo one that can be maintained by the entire team and checked in.

Motivation

This allows us consistancy in maintaining the authors file, and all the advantages of it being tracked by git (history, blame, etc).

Describe alternatives you've considered

Using the env variable GITMOB_COAUTHORS_PATH doesn't work as we work with many repos which belong to different teams.

Additional context

I am willing to submit a PR if that would help. Its an easy enough change. Something to the following file https://github.com/rkotze/git-mob/blob/master/packages/git-mob-core/src/git-mob-api/git-authors/index.js#L107-L111 like:

const { silentRun } = require('../silent-run');

function pathToCoAuthors() {
  if (process.env.GITMOB_COAUTHORS_PATH) {
    return process.env.GITMOB_COAUTHORS_PATH;
  }

  const gitCoAuthorsFilename = process.env.fetch("GITMOB_COAUTHORS_FILENAME", ".git-coauthors");
  const repoAuthorsFile = path.join(gitRootDir(), gitCoAuthorsFilename);

  return fs.existsSync(repoAuthorsFile)
    ? repoAuthorsFile
    : path.join(os.homedir(), gitCoAuthorsFilename);
}

function gitRootDir(gitCoAuthorsFilename) {
  const response = silentRun("git rev-parse --show-toplevel");
  return response.stdout.trim();
}
tlabeeuw commented 1 year ago

Obviously the PR would need to add tests and actually cope with errors and such. Also there is a second place that would need to change: https://github.com/rkotze/git-mob/blob/master/packages/git-mob/src/git-authors/index.js#L7-L8.

And don't know if the env var GITMOB_COAUTHORS_FILENAME is really necessary. Maybe requires too many changes since this is hard coded all over the place.

rkotze commented 1 year ago

Hi @tlabeeuw

I like the idea of having a local .git-coauthors file overriding the global co-authors.

I don't think there is a need to provide an env var to change the file name GITMOB_COAUTHORS_FILENAME prefer to keep this internal.

At the moment I'm migrating to use git-mob-core package which is why there are two references to figuring out the path.

It would be handy to provide a config with a relative path to help organise where the file lives in the repo.

It would be great if you could create a PR for this. Please comment if you do decide to and assign yourself. Thanks.

Your suggested changes look to be in the correct place and you can get the root dir here.

Please read the small contribution guide.

tlabeeuw commented 1 year ago

Great thanks @rkotze,

I will submit a PR by End of Week. Ill duplicate the code in both areas.

rkotze commented 1 year ago

Thanks for your contribution @tlabeeuw. Released in git mob v2.4.0.