Skip to content

Commit

Permalink
修复:"setgit-cli" v1.1.4 并没能成功配置 Git
Browse files Browse the repository at this point in the history
  • Loading branch information
iTonyYo committed Jun 8, 2021
1 parent 90df415 commit 360864e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 50 deletions.
8 changes: 4 additions & 4 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions scripts/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ async function rollupBuild() {
const bundle = await rollup({
input: srcRollupEntryPath,
external: [
"meow",
"update-notifier",

"cosmiconfig",

"meow",
"gradient-string",
"is-git-repository",
"redent",
"chalk",

"is-git-repository",
"nodegit",
"async/eachOfLimit",

"deepmerge",

"async/eachOfSeries",
"async/asyncify",
],
plugins: [json(), terser(), prepend("#!/usr/bin/env node")],
Expand Down
38 changes: 38 additions & 0 deletions src/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default {
twd: ".",
configs: {
"alias.ls": "ls-files",
"alias.remotes": "remote -v",

"alias.amend":
"!git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend",
"alias.fixup": "commit --fixup=HEAD",

"core.ignorecase": "false",

"alias.s": "status",
"alias.p": "push",
"alias.b": "branch -a -v",
"alias.cm": "commit -m",
"alias.tags": "tag -l",
"alias.co": "checkout",
"alias.all": "add -A",
"alias.pl": "pull --ff-only",
"alias.stashes": "stash list",
"alias.med": "merge develop",
"alias.mem": "merge master",

"alias.l": "log --oneline --color -6",
"alias.out": "log @{u}..",
"alias.la":
"log -16 --color=always --all --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative",
"alias.ll":
"log --color=always --all --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit",
"alias.lg":
"log -10 --color=always --all --graph --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative",
"alias.lgl":
"log --color=always --all --graph --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit",

"alias.wdiff": "diff --color-words",
},
};
54 changes: 11 additions & 43 deletions src/setGit.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
import { Repository } from "nodegit";

import eachOfLimit from "async/eachOfLimit";
import eachOfSeries from "async/eachOfSeries";
import asyncify from "async/asyncify";

export default async function setGit(options = { twd: ".", configs: {} }) {
const { twd, configs } = Object.assign(
{
twd: ".",
configs: {
"alias.ls": "ls-files",
"alias.remotes": "remote -v",

"alias.amend":
"!git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend",
"alias.fixup": "commit --fixup=HEAD",

"core.ignorecase": "false",
import deepmerge from "deepmerge";

"alias.s": "status",
"alias.p": "push",
"alias.b": "branch -a -v",
"alias.cm": "commit -m",
"alias.tags": "tag -l",
"alias.co": "checkout",
"alias.all": "add -A",
"alias.pl": "pull --ff-only",
"alias.stashes": "stash list",
"alias.med": "merge develop",
"alias.mem": "merge master",
import preset from "./preset";

"alias.l": "log --oneline --color -6",
"alias.out": "log @{u}..",
"alias.la":
"log -16 --color=always --all --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative",
"alias.ll":
"log --color=always --all --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit",
"alias.lg":
"log -10 --color=always --all --graph --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative",
"alias.lgl":
"log --color=always --all --graph --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit",

"alias.wdiff": "diff --color-words",
},
},
options
);
export default async function setGit(options = { twd: ".", configs: {} }) {
const cfg = deepmerge(preset, options);
const { twd, configs } = cfg;

const repo = await Repository.open(twd);

Expand All @@ -54,9 +19,12 @@ export default async function setGit(options = { twd: ".", configs: {} }) {
async function setter({ repo, configs }) {
const gitConfiger = await repo.config();

await eachOfLimit(
/**
* NOTE: 必须串行!
* 并行配置 Git 时,Git 会反复创建 ”.git/config.lock“ 文件,但这是不合法的,最终程序报错
*/
await eachOfSeries(
configs,
4,
asyncify(async (val, key) => {
await gitConfiger.setString(key, val);
return;
Expand Down

0 comments on commit 360864e

Please sign in to comment.