Skip to content

Commit

Permalink
Merge pull request #78 from rkotze/global-mob
Browse files Browse the repository at this point in the history
✨ Change git mob to work globally
  • Loading branch information
rkotze authored Jul 2, 2022
2 parents 735d8bb + e8aebd1 commit f63c883
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 8,913 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ Read our blog post to find out why git-mob exists: [Co-author commits with Git M

![gif showing example usage of git-mob](https://user-images.githubusercontent.com/497458/38682926-2e0cc99c-3e64-11e8-9f71-6336e111005b.gif)

1. [Install](#install)
2. [Using `git commit -m`](#using-git-commit--m-setup)
3. [Workflow / Usage](#workflow--usage)
4. [How to contribute](https://github.com/rkotze/git-mob/blob/master/CONTRIBUTING.md)
5. [More commands](#more-commands)
1. [List all co-authors](#list-all-co-authors)
2. [Overwrite the main author](#list-all-co-authors)
3. [Add co-author](#add-co-author)
4. [Delete co-author](#delete-co-author)
5. [Edit co-author](#edit-co-author)
6. [Add initials of current mob to PS1, in bash and fish](#add-initials-of-current-mob-to-your-prompt)
- [Install](#install)
- [Using `git commit -m` setup](#using-git-commit--m-setup)
- [Revert back to default setup](#revert-back-to-default-setup)
- [Workflow / Usage](#workflow--usage)
- [More commands](#more-commands)
- [List all co-authors](#list-all-co-authors)
- [Overwrite the main author](#overwrite-the-main-author)
- [Add co-author](#add-co-author)
- [Delete co-author](#delete-co-author)
- [Edit co-author](#edit-co-author)
- [Suggest co-authors base on current repo](#suggest-co-authors-base-on-current-repo)
- [Add initials of current mob to your prompt](#add-initials-of-current-mob-to-your-prompt)
- [Bash](#bash)
- [Fish](#fish)

## Install

Expand All @@ -32,7 +35,7 @@ git-mob is a CLI tool, so you'll need to install the package globally.
npm i -g git-mob
```

By default git-mob will use the `.gitmessage` template to append co-authors.
By default git-mob will use the **global** config `.gitmessage` template to append co-authors.

### Using `git commit -m` setup

Expand All @@ -45,7 +48,6 @@ How to append co-authors to the message when using message flag - `git commit -m

The command `git mob-print` will output to `stdout` the formatted co-authors.


**Note:** > `v1.1.0` `git mob --installTemplate` and `git mob --uninstallTemplate` has been removed.

### Revert back to default setup
Expand Down Expand Up @@ -95,7 +97,11 @@ $ cat <<-EOF > ~/.git-coauthors
EOF
```

You're ready to create your mob. Tell git-mob you're pairing with Amy by using her initials.
You're ready to create your mob. Tell git-mob you're pairing with Amy by using her initials. `git mob ad`

Selected co-authors are **stored globally** meaning when switching between projects your co-authors stay the same*.

***Note**: If you've set a **local** commit template in your config then that template will be updated. However, **not** when you switch projects and you will see a warning. [Read more here](https://github.com/rkotze/git-mob/discussions/81)

```
$ git mob ad
Expand Down
24 changes: 18 additions & 6 deletions bin/mob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node
const minimist = require('minimist');
const { oneLine } = require('common-tags');
const { oneLine, stripIndents } = require('common-tags');

const { config, revParse } = require('../src/git-commands');
const { gitAuthors } = require('../src/git-authors');
Expand All @@ -16,7 +16,7 @@ const {
printList,
} = require('../src/helpers');
const { configWarning } = require('../src/check-author');
const { RED } = require('../src/constants');
const { red, yellow } = require('../src/colours');
const { getCoAuthors, isCoAuthorSet, resetMob, addCoAuthor, getGitAuthor, setGitAuthor } = require('../src/git-mob-commands');

checkForUpdates();
Expand Down Expand Up @@ -51,7 +51,7 @@ async function execute(args) {
}

if (!revParse.insideWorkTree()) {
console.error('Error: not a git repository');
console.error('Error: not a Git repository');
process.exit(1);
}

Expand All @@ -78,8 +78,14 @@ function printMob() {
console.log(getCoAuthors());
}

if (config.usingLocalTemplate()) {
console.log(yellow(stripIndents`Warning: Git Mob uses Git global config.
Using local commit.template could mean your template does not have selected co-authors appended after switching projects.
See: https://github.com/rkotze/git-mob/discussions/81`));
}

if (configWarning(gitAuthor)) {
console.warn(RED, configWarning(gitAuthor));
console.warn(red(configWarning(gitAuthor)));
}
}

Expand Down Expand Up @@ -113,6 +119,12 @@ async function setMob(initials) {
coauthors
);

if (config.usingLocalTemplate() && config.usingGlobalTemplate()) {
gitMessage(config.getGlobalTemplate()).writeCoAuthors(
coauthors
);
}

printMob();
} catch (error) {
console.error(`Error: ${error.message}`);
Expand All @@ -139,7 +151,7 @@ function author({ name, email }) {
}

function setCommitTemplate() {
if (!config.has('commit.template')) {
config.set('commit.template', commitTemplatePath());
if (!config.hasTemplatePath()) {
config.setTemplatePath(commitTemplatePath());
}
}
7 changes: 6 additions & 1 deletion bin/solo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const minimist = require('minimist');
const { oneLine } = require('common-tags');

const { revParse } = require('../src/git-commands');
const { revParse, config } = require('../src/git-commands');
const {
gitMessage,
gitMessagePath,
Expand Down Expand Up @@ -41,6 +41,11 @@ async function runSolo(_args) {
try {
await gitMessage(gitMessagePath()
).removeCoAuthors();

if (config.usingLocalTemplate() && config.usingGlobalTemplate()) {
gitMessage(config.getGlobalTemplate()).removeCoAuthors();
}

resetMob();
printAuthor();
} catch (error) {
Expand Down
Loading

0 comments on commit f63c883

Please sign in to comment.