Skip to content

Commit 2f5fbeb

Browse files
authored
feat: rename (#6)
1 parent de14633 commit 2f5fbeb

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
## Change log
22

3-
**0.2.0**
3+
**1.4.0**
4+
5+
- Support command `rename`
6+
7+
**1.3.0**
8+
9+
- Nothing, I'm not sure why it was a major 🤨
10+
11+
**1.2.0**
412

513
- Support commands `stash` and `diff` (also added webpack + typescript)
614

7-
**0.1.0**
15+
**1.1.0**
816

917
- Support commands `add` and `reset`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ git-wiz
3131
- `reset`
3232
- `stash`
3333
- `diff`
34+
- `rename` (`mv`)
3435

3536
## Development
3637

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-wiz",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"author": {
55
"email": "moshfeu.dev@gmail.com",
66
"name": "Mosh Feu",
@@ -31,15 +31,15 @@
3131
],
3232
"dependencies": {
3333
"commander": "^6.1.0",
34-
"inquirer": "^7.3.3",
35-
"ts-loader": "^8.0.3",
36-
"typescript": "^4.0.2"
34+
"inquirer": "^7.3.3"
3735
},
3836
"devDependencies": {
3937
"@types/inquirer": "^7.3.1",
4038
"json-loader": "^0.5.7",
4139
"webpack": "^4.44.1",
4240
"webpack-cli": "^3.3.12",
43-
"webpack-node-externals": "^2.5.2"
41+
"webpack-node-externals": "^2.5.2",
42+
"ts-loader": "^8.0.3",
43+
"typescript": "^4.0.2"
4444
}
4545
}

src/utils/git.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execCommand } from './exec';
2+
import { basename } from 'path';
23

34
type File = {
45
status: 'tracked' | 'staged' | 'untracked';
@@ -72,9 +73,17 @@ export async function gitReset(files: Array<string>) {
7273
export async function gitStash(files: Array<string>, message?: string) {
7374
await gitAdd(files);
7475
// sorry for the 'replace', the space conflicts with: https://github.com/spread-the-code/git-wiz/blob/134f7cb9053cc20edcb0b969848d39d836b0ce31/src/utils/exec.ts#L6
75-
await runCommand(`stash push${message ? ` -m ${message.replace(/ /g, '-')}` : ''}`, files);
76+
await runCommand(
77+
`stash push${message ? ` -m ${message.replace(/ /g, '-')}` : ''}`,
78+
files
79+
);
7680
}
7781

7882
export function gitDiff(files: Array<string>, flags: Array<string>) {
7983
return runCommand('diff', files, flags, true);
8084
}
85+
86+
export function gitMv(path: string, newName: string) {
87+
const newPath = path.replace(basename(path), newName);
88+
return runCommand('mv', [], [path, newPath]);
89+
}

src/utils/program.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { program } from 'commander';
2-
import { add, diff, reset, stash } from './wiz';
2+
import { add, diff, rename, reset, stash } from './wiz';
33
import { version } from '../../package.json';
44

55
export function init() {
@@ -29,6 +29,13 @@ export function init() {
2929
)
3030
.action(diff);
3131

32+
program
33+
.command('rename <path> <newName>')
34+
.description(
35+
'do "git mv" (for renaming) with style 🔖'
36+
)
37+
.action(rename);
38+
3239
program.parse(process.argv);
3340
} catch (error) {
3441
console.log(error);

src/utils/wiz.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from 'commander';
22
import { showFilesChooser, showFilesChooserAnd } from './cli';
3-
import { gitStatus, gitAdd, gitReset, gitStash, gitDiff } from './git';
3+
import { gitStatus, gitAdd, gitReset, gitStash, gitDiff, gitMv } from './git';
44

55
export const add = withErrorHandler(async () => {
66
const status = (await gitStatus()).filter((file) => file.status !== 'staged');
@@ -67,6 +67,10 @@ export const diff = withErrorHandler(async (comObj: Command) => {
6767
await gitDiff(files, comObj.args);
6868
});
6969

70+
export const rename = withErrorHandler(async ({args: [path, newName]}: Command) => {
71+
await gitMv(path, newName);
72+
});
73+
7074
function withErrorHandler(fn: Function) {
7175
return (...args: Array<unknown>): Promise<void> => {
7276
try {

0 commit comments

Comments
 (0)