-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
183 lines (160 loc) · 4.57 KB
/
cli.js
File metadata and controls
183 lines (160 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env node
import { Command } from 'commander';
import GitManager from './index.js';
const program = new Command();
const gitManager = new GitManager();
program
.name('Gitpilot')
.description('Git operations')
.version('1.0.0');
// Commit command
program
.command('commit <message>')
.description('Commit changes with a message')
.action(async (message) => {
await gitManager.commit(message);
});
// Push command
program
.command('push [branch]')
.description('Push changes to a branch (default is main)')
.action(async (branch = 'main') => {
await gitManager.push(branch);
});
/* Timed commits */
// Backdate commit command
program
.command('backdate <message> <date>')
.description('Commit changes with a past date (use yyyy-mm-dd date format)')
.action(async (message, date) => {
await gitManager.timedCommit(message, date);
});
// Timed commit command
program
.command('commitOn <message> <date>')
.description('Commit changes with a past date (use yyyy-mm-dd date format)')
.action(async (message, date) => {
await gitManager.timedCommit(message, date);
});
// Timed commit command
program
.command('commiton <message> <date>')
.description('Commit changes with a past date (use yyyy-mm-dd date format)')
.action(async (message, date) => {
await gitManager.timedCommit(message, date);
});
/* Timed commits */
// Pull command
program
.command('pull [branch]')
.description('Pull changes from a branch (default is main)')
.action(async (branch = 'main') => {
await gitManager.pull(branch);
});
// Create a new branch and switch to it
program
.command('create-branch <branchName>')
.description('Create a new branch and switch to it')
.action(async (branchName) => {
await gitManager.createBranch(branchName);
});
// List all branches
program
.command('list-branches')
.description('List all branches in the repository')
.action(async () => {
await gitManager.listBranches();
});
// Delete a local branch
program
.command('delete-branch <branchName>')
.description('Delete a local branch')
.action(async (branchName) => {
await gitManager.deleteBranch(branchName);
});
// Create an annotated tag
program
.command('create-tag <tagName> <message>')
.description('Create an annotated tag with a message')
.action(async (tagName, message) => {
await gitManager.createTag(tagName, message);
});
// List all tags
program
.command('list-tags')
.description('List all tags in the repository')
.action(async () => {
await gitManager.listTags();
});
// Stash changes
program
.command('stash')
.description('Stash changes')
.action(async () => {
await gitManager.stashChanges();
});
// Apply stash by index
program
.command('apply-stash [stashIndex]')
.description('Apply a stash by its index (default is 0)')
.action(async (stashIndex = 0) => {
await gitManager.applyStash(stashIndex);
});
// List all stashes
program
.command('list-stashes')
.description('List all stashes')
.action(async () => {
await gitManager.listStashes();
});
// Undo the last commit
program
.command('undo-last-commit')
.description('Undo the last commit')
.action(async () => {
await gitManager.undoLastCommit();
});
// Unstage files
program
.command('unstage <files...>')
.description('Unstage files (provide a list of file paths)')
.action(async (files) => {
await gitManager.unstageFiles(files);
});
// Amend the last commit
program
.command('amend-commit <message>')
.description('Amend the previous commit with a new message')
.action(async (message) => {
await gitManager.amendCommit(message);
});
// Cherry-pick a commit by hash
program
.command('cherry-pick <commitHash>')
.description('Cherry-pick a commit by its hash')
.action(async (commitHash) => {
await gitManager.cherryPick(commitHash);
});
// Resolve merge conflicts
program
.command('resolve-conflicts')
.description('Check and resolve merge conflicts')
.action(async () => {
await gitManager.resolveConflicts();
});
// Set Git configuration
program
.command('set-config <key> <value> [global]')
.description('Set Git config (use "global" flag for global config)')
.action(async (key, value, global) => {
const isGlobal = global === 'global';
await gitManager.setGitConfig(key, value, isGlobal);
});
// Get Git configuration
program
.command('get-config <key>')
.description('Get Git config value by key')
.action(async (key) => {
await gitManager.getGitConfig(key);
});
program.parse(process.argv);