@teambit/git 1.0.108 → 1.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/preview/teambit_git_git-preview.js +1 -0
- package/package.json +5 -5
- package/git.aspect.ts +0 -5
- package/git.cmd.ts +0 -20
- package/git.main.runtime.ts +0 -133
- package/index.ts +0 -5
- package/merge-bitmaps.cmd.ts +0 -30
- package/set-git-merge-driver.cmd.ts +0 -29
- /package/dist/{preview-1703647408454.js → preview-1703698405864.js} +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.git/git-preview"]=t():e["teambit.git/git-preview"]=t()}(self,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var i in o)e.o(o,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:o[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{compositions:()=>o,compositions_metadata:()=>r,overview:()=>i});const o=[],i=[],r={compositions:[]};return t})()));
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/git",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.109",
|
4
4
|
"homepage": "https://bit.cloud/teambit/git/git",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.git",
|
8
8
|
"name": "git",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.109"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "2.4.2",
|
@@ -14,15 +14,15 @@
|
|
14
14
|
"gitconfig": "2.0.8",
|
15
15
|
"@teambit/harmony": "0.4.6",
|
16
16
|
"@teambit/bit-error": "0.0.404",
|
17
|
-
"@teambit/cli": "0.0.
|
18
|
-
"@teambit/workspace": "1.0.
|
17
|
+
"@teambit/cli": "0.0.841",
|
18
|
+
"@teambit/workspace": "1.0.109"
|
19
19
|
},
|
20
20
|
"devDependencies": {
|
21
21
|
"@types/fs-extra": "9.0.7",
|
22
22
|
"@types/mocha": "9.1.0",
|
23
23
|
"@types/jest": "^29.2.2",
|
24
24
|
"@types/testing-library__jest-dom": "^5.9.5",
|
25
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
25
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
28
|
"@teambit/legacy": "1.0.624"
|
package/git.aspect.ts
DELETED
package/git.cmd.ts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Command } from '@teambit/cli';
|
2
|
-
import chalk from 'chalk';
|
3
|
-
|
4
|
-
const COMMAND_NAME = 'git';
|
5
|
-
|
6
|
-
export class GitCmd implements Command {
|
7
|
-
name = `${COMMAND_NAME} <sub-command>`;
|
8
|
-
alias = '';
|
9
|
-
description = 'perform git operations';
|
10
|
-
options = [];
|
11
|
-
group = 'git';
|
12
|
-
commands: Command[] = [];
|
13
|
-
// helpUrl = '';
|
14
|
-
|
15
|
-
async report([unrecognizedSubcommand]: [string]) {
|
16
|
-
return chalk.red(
|
17
|
-
`"${unrecognizedSubcommand}" is not a subcommand of "git", please run "bit git --help" to list the subcommands`
|
18
|
-
);
|
19
|
-
}
|
20
|
-
}
|
package/git.main.runtime.ts
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
import fs from 'fs-extra';
|
2
|
-
import { BitError } from '@teambit/bit-error';
|
3
|
-
import { homedir } from 'os';
|
4
|
-
import { join } from 'path';
|
5
|
-
import gitconfig from 'gitconfig';
|
6
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
7
|
-
import { WorkspaceAspect, Workspace, BitmapMergeOptions } from '@teambit/workspace';
|
8
|
-
import { GitAspect } from './git.aspect';
|
9
|
-
import { MergeBitmapsCmd } from './merge-bitmaps.cmd';
|
10
|
-
import { SetGitMergeDriverCmd } from './set-git-merge-driver.cmd';
|
11
|
-
import { GitCmd } from './git.cmd';
|
12
|
-
|
13
|
-
type SetGitMergeDriverOpts = {
|
14
|
-
global?: boolean;
|
15
|
-
};
|
16
|
-
|
17
|
-
const GIT_BASE_KEY = 'merge.bitmap-driver';
|
18
|
-
const GIT_NAME_KEY = `${GIT_BASE_KEY}.name`;
|
19
|
-
const GIT_DRIVER_KEY = `${GIT_BASE_KEY}.driver`;
|
20
|
-
|
21
|
-
const GIT_NAME_VALUE = 'A custom merge driver used to resolve conflicts in .bitmap files';
|
22
|
-
// const binName = process.argv[1];
|
23
|
-
const GIT_DRIVER_VALUE = 'bd git merge-bitmaps %O %A %B';
|
24
|
-
|
25
|
-
const GIT_ATTRIBUTES = '.bitmap merge=bitmap-driver';
|
26
|
-
|
27
|
-
export interface GitExtWorkspaceConfig {
|
28
|
-
mergeStrategy: 'ours' | 'theirs' | 'manual';
|
29
|
-
}
|
30
|
-
export class GitMain {
|
31
|
-
constructor(
|
32
|
-
private workspace: Workspace,
|
33
|
-
/**
|
34
|
-
* Git extension configuration.
|
35
|
-
*/
|
36
|
-
readonly config: GitExtWorkspaceConfig
|
37
|
-
) {}
|
38
|
-
|
39
|
-
async mergeBitmaps(ancestor: string, current: string, other: string) {
|
40
|
-
const encoding = 'utf-8';
|
41
|
-
// const ancestorContent = this.stripBom(fs.readFileSync(ancestor, encoding));
|
42
|
-
const currentContent = this.stripBom(fs.readFileSync(current, encoding));
|
43
|
-
const otherContent = this.stripBom(fs.readFileSync(other, encoding));
|
44
|
-
const opts: BitmapMergeOptions = {
|
45
|
-
mergeStrategy: this.config.mergeStrategy || 'manual',
|
46
|
-
};
|
47
|
-
const merged = this.workspace.bitMap.mergeBitmaps(currentContent, otherContent, opts);
|
48
|
-
await fs.outputFile(current, merged);
|
49
|
-
return merged;
|
50
|
-
}
|
51
|
-
|
52
|
-
async setGitMergeDriver(opts: SetGitMergeDriverOpts) {
|
53
|
-
await this.setGitConfig(opts);
|
54
|
-
await this.setGitAttributes(opts);
|
55
|
-
return true;
|
56
|
-
}
|
57
|
-
|
58
|
-
private async setGitConfig(opts: SetGitMergeDriverOpts) {
|
59
|
-
const isGit = await fs.pathExists('.git');
|
60
|
-
if (!isGit && !opts.global) {
|
61
|
-
throw new BitError('This is not a git repository');
|
62
|
-
}
|
63
|
-
const location = opts.global ? 'global' : 'local';
|
64
|
-
let gitVal;
|
65
|
-
try {
|
66
|
-
gitVal = await gitconfig.get(GIT_NAME_KEY, { location });
|
67
|
-
} catch {
|
68
|
-
// do nothing, it just means that there is no config yet which is fine
|
69
|
-
}
|
70
|
-
if (gitVal) {
|
71
|
-
return; // already set
|
72
|
-
}
|
73
|
-
await gitconfig.set(GIT_NAME_KEY, GIT_NAME_VALUE, { location });
|
74
|
-
await gitconfig.set(GIT_DRIVER_KEY, GIT_DRIVER_VALUE, { location });
|
75
|
-
}
|
76
|
-
|
77
|
-
private async setGitAttributes(opts: SetGitMergeDriverOpts) {
|
78
|
-
const attributesPath = await this.getGitAttributesPath(opts.global);
|
79
|
-
const isGit = await fs.pathExists('.git');
|
80
|
-
if (!isGit && !opts.global) {
|
81
|
-
throw new BitError('This is not a git repository');
|
82
|
-
}
|
83
|
-
const fileExist = await fs.pathExists(attributesPath);
|
84
|
-
if (!fileExist) {
|
85
|
-
await fs.writeFile(attributesPath, GIT_ATTRIBUTES);
|
86
|
-
} else {
|
87
|
-
const gitAttributes = await fs.readFile(attributesPath, 'utf8');
|
88
|
-
if (gitAttributes.includes(GIT_ATTRIBUTES)) {
|
89
|
-
return; // already set
|
90
|
-
}
|
91
|
-
await fs.appendFile(attributesPath, `\n${GIT_ATTRIBUTES}`);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
private async getGitAttributesPath(global = false) {
|
96
|
-
const fromConfig = await gitconfig.get('core.attributesFile', { location: global ? 'global' : 'local' });
|
97
|
-
if (fromConfig) {
|
98
|
-
return fromConfig;
|
99
|
-
}
|
100
|
-
if (!global) {
|
101
|
-
return '.gitattributes';
|
102
|
-
}
|
103
|
-
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
|
104
|
-
if (xdgConfigHome) {
|
105
|
-
return join(xdgConfigHome, 'git', 'attributes');
|
106
|
-
}
|
107
|
-
return join(homedir(), '.config', 'git', 'attributes');
|
108
|
-
}
|
109
|
-
|
110
|
-
private stripBom(str) {
|
111
|
-
return str[0] === '\uFEFF' ? str.slice(1) : str;
|
112
|
-
}
|
113
|
-
|
114
|
-
static slots = [];
|
115
|
-
// define your aspect dependencies here.
|
116
|
-
// in case you need to use another aspect API.
|
117
|
-
static dependencies = [CLIAspect, WorkspaceAspect];
|
118
|
-
|
119
|
-
static runtime = MainRuntime;
|
120
|
-
|
121
|
-
static async provider([cli, workspace]: [CLIMain, Workspace], config: GitExtWorkspaceConfig) {
|
122
|
-
const gitMain = new GitMain(workspace, config);
|
123
|
-
const gitCmd = new GitCmd();
|
124
|
-
gitCmd.commands = [new SetGitMergeDriverCmd(gitMain), new MergeBitmapsCmd(gitMain)];
|
125
|
-
cli.register(gitCmd);
|
126
|
-
cli.registerGroup('git', 'Git');
|
127
|
-
return gitMain;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
GitAspect.addRuntime(GitMain);
|
132
|
-
|
133
|
-
export default GitMain;
|
package/index.ts
DELETED
package/merge-bitmaps.cmd.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
2
|
-
import chalk from 'chalk';
|
3
|
-
import { GitMain } from './git.main.runtime';
|
4
|
-
|
5
|
-
const COMMAND_NAME = 'merge-bitmaps';
|
6
|
-
|
7
|
-
// - `%O`: ancestor’s version of the conflicting file
|
8
|
-
// - `%A`: current version of the conflicting file
|
9
|
-
// - `%B`: other branch's version of the conflicting file
|
10
|
-
|
11
|
-
export class MergeBitmapsCmd implements Command {
|
12
|
-
name = `${COMMAND_NAME} <ancestor> <current> <other>`;
|
13
|
-
alias = '';
|
14
|
-
description = `a special command to merge conflicting bitmap files during git merge`;
|
15
|
-
options = [] as CommandOptions;
|
16
|
-
group = 'git';
|
17
|
-
commands: Command[] = [];
|
18
|
-
private = true;
|
19
|
-
// helpUrl = '';
|
20
|
-
|
21
|
-
constructor(private git: GitMain) {}
|
22
|
-
|
23
|
-
async report([ancestor, current, other]: string[]) {
|
24
|
-
const res = await this.git.mergeBitmaps(ancestor, current, other);
|
25
|
-
if (res) {
|
26
|
-
return chalk.green('git merge driver was successfully set');
|
27
|
-
}
|
28
|
-
return chalk.red('git merge driver was not set');
|
29
|
-
}
|
30
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
2
|
-
import chalk from 'chalk';
|
3
|
-
import { GitMain } from './git.main.runtime';
|
4
|
-
|
5
|
-
const COMMAND_NAME = 'set-merge-driver';
|
6
|
-
|
7
|
-
type SetGitMergeDriverFlags = {
|
8
|
-
global?: boolean;
|
9
|
-
};
|
10
|
-
|
11
|
-
export class SetGitMergeDriverCmd implements Command {
|
12
|
-
name = COMMAND_NAME;
|
13
|
-
alias = 'smd';
|
14
|
-
description = `setup bit's git merge driver for bitmap files`;
|
15
|
-
options = [['g', 'global', 'set the git merge driver globally']] as CommandOptions;
|
16
|
-
group = 'git';
|
17
|
-
commands: Command[] = [];
|
18
|
-
// helpUrl = '';
|
19
|
-
|
20
|
-
constructor(private git: GitMain) {}
|
21
|
-
|
22
|
-
async report(_args, flags: SetGitMergeDriverFlags) {
|
23
|
-
const res = await this.git.setGitMergeDriver(flags);
|
24
|
-
if (res) {
|
25
|
-
return chalk.green('git merge driver was successfully set');
|
26
|
-
}
|
27
|
-
return chalk.red('git merge driver was not set');
|
28
|
-
}
|
29
|
-
}
|
File without changes
|