Skip to content

Commit 769bacc

Browse files
committed
fixes #442: addAllUnstagedFiles now has the correct behavior
1 parent adb91e6 commit 769bacc

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

jupyterlab_git/git.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,17 @@ def add_all(self, top_repo_path):
539539
my_output = subprocess.check_output(["git", "add", "-A"], cwd=top_repo_path)
540540
return my_output
541541

542+
def add_all_unstaged(self, top_repo_path):
543+
"""
544+
Execute git add all unstaged command & return the result.
545+
"""
546+
e = 'git add -u'
547+
my_output = subprocess.call(e, shell=True, cwd=top_repo_path)
548+
return {"result": my_output}
549+
542550
def add_all_untracked(self, top_repo_path):
543551
"""
544-
Execute git add_all_untracked command & return the result.
552+
Execute git add all untracked command & return the result.
545553
"""
546554
e = 'echo "a\n*\nq\n" | git add -i'
547555
my_output = subprocess.call(e, shell=True, cwd=top_repo_path)

jupyterlab_git/handlers.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def post(self):
182182
my_output = self.git.diff(top_repo_path)
183183
self.finish(my_output)
184184

185+
185186
class GitBranchHandler(GitHandler):
186187
"""
187188
Handler for 'git branch -a'. Fetches list of all branches in current repository
@@ -199,12 +200,12 @@ def post(self):
199200
class GitAddHandler(GitHandler):
200201
"""
201202
Handler for git add <filename>'.
202-
Adds one or all files into to the staging area.
203+
Adds one or all files to the staging area.
203204
"""
204205

205206
def get(self):
206207
"""
207-
GET request handler, adds files in the staging area.
208+
GET request handler, adds files to the staging area.
208209
"""
209210
self.finish(
210211
json.dumps(
@@ -226,6 +227,40 @@ def post(self):
226227
self.finish(my_output)
227228

228229

230+
class GitAddAllUnstagedHandler(GitHandler):
231+
"""
232+
Handler for 'git add -u'. Adds ONLY all unstaged files, does not touch
233+
untracked or staged files.
234+
"""
235+
236+
def post(self):
237+
"""
238+
POST request handler, adds all the changed files.
239+
"""
240+
self.finish(
241+
self.git.add_all_unstaged(
242+
self.get_json_body()["top_repo_path"]
243+
)
244+
)
245+
246+
247+
class GitAddAllUntrackedHandler(GitHandler):
248+
"""
249+
Handler for 'echo "a\n*\nq\n" | git add -i'. Adds ONLY all
250+
untracked files, does not touch unstaged or staged files.
251+
"""
252+
253+
def post(self):
254+
"""
255+
POST request handler, adds all the untracked files.
256+
"""
257+
self.finish(
258+
self.git.add_all_untracked(
259+
self.get_json_body()["top_repo_path"]
260+
)
261+
)
262+
263+
229264
class GitResetHandler(GitHandler):
230265
"""
231266
Handler for 'git reset <filename>'.
@@ -344,7 +379,7 @@ def post(self):
344379
"""
345380
data = self.get_json_body()
346381
response = self.git.pull(data['current_path'], data.get('auth', None))
347-
382+
348383
self.finish(json.dumps(response))
349384

350385

@@ -404,18 +439,6 @@ def post(self):
404439
self.finish(my_output)
405440

406441

407-
class GitAddAllUntrackedHandler(GitHandler):
408-
"""
409-
Handler for 'echo "a\n*\nq\n" | git add -i'. Adds ONLY all untracked files.
410-
"""
411-
412-
def post(self):
413-
"""
414-
POST request handler, adds all the untracked files.
415-
"""
416-
top_repo_path = self.get_json_body()["top_repo_path"]
417-
my_output = self.git.add_all_untracked(top_repo_path)
418-
self.finish(my_output)
419442

420443
class GitChangedFilesHandler(GitHandler):
421444

@@ -466,6 +489,8 @@ def setup_handlers(web_app):
466489
("/git/show_top_level", GitShowTopLevelHandler),
467490
("/git/show_prefix", GitShowPrefixHandler),
468491
("/git/add", GitAddHandler),
492+
("/git/add_all_unstaged", GitAddAllUnstagedHandler),
493+
("/git/add_all_untracked", GitAddAllUntrackedHandler),
469494
("/git/status", GitStatusHandler),
470495
("/git/branch", GitBranchHandler),
471496
("/git/reset", GitResetHandler),
@@ -480,7 +505,6 @@ def setup_handlers(web_app):
480505
("/git/detailed_log", GitDetailedLogHandler),
481506
("/git/init", GitInitHandler),
482507
("/git/all_history", GitAllHistoryHandler),
483-
("/git/add_all_untracked", GitAddAllUntrackedHandler),
484508
("/git/clone", GitCloneHandler),
485509
("/git/upstream", GitUpstreamHandler),
486510
("/git/config", GitConfigHandler),

src/components/FileList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
312312

313313
/** Add all unstaged files */
314314
addAllUnstagedFiles = async () => {
315-
await this.props.model.add();
315+
await this.props.model.addAllUnstaged();
316316
};
317317

318318
/** Discard changes in all unstaged files */

src/model.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,38 @@ export class GitExtension implements IGitExtension, IDisposable {
464464
return Promise.resolve(response);
465465
}
466466

467+
/** Make request to add all unstaged files into
468+
* the staging area in repository 'path'
469+
*/
470+
async addAllUnstaged(): Promise<Response> {
471+
await this.ready;
472+
const path = this.pathRepository;
473+
474+
if (path === null) {
475+
return Promise.resolve(
476+
new Response(
477+
JSON.stringify({
478+
code: -1,
479+
message: 'Not in a git repository.'
480+
})
481+
)
482+
);
483+
}
484+
485+
try {
486+
let response = await httpGitRequest('/git/add_all_unstaged', 'POST', {
487+
top_repo_path: path
488+
});
489+
if (response.status !== 200) {
490+
const data = await response.json();
491+
throw new ServerConnection.ResponseError(response, data.message);
492+
}
493+
return response.json();
494+
} catch (err) {
495+
throw ServerConnection.NetworkError;
496+
}
497+
}
498+
467499
/** Make request to add all untracked files into
468500
* the staging area in the repository
469501
*/

0 commit comments

Comments
 (0)