diff --git a/lib/oto/commands/git/git.dart b/lib/oto/commands/git/git.dart index 8ac401f..8c2d3a3 100644 --- a/lib/oto/commands/git/git.dart +++ b/lib/oto/commands/git/git.dart @@ -24,19 +24,17 @@ class GitPush extends Command { @override Future execute(DataCommand command) async { var data = DataGitPush.fromJson(getParam(command)); - + var shell = StringBuffer(getCDPath(workspace)); - if(data.branch == null) - { + if (data.branch == null) { shell.write(' && git push'); - } - else - { + } else { shell.write(' && git push origin ${data.branch!}'); } var process = await ProcessExecutor.start(shell); - return await completeProcess(process, command, passExitCodes: [1 /*Everything up-to-date*/]); + return await completeProcess(process, command, + passExitCodes: [1 /*Everything up-to-date*/]); } } @@ -53,26 +51,23 @@ class GitCheckout extends Git { var process = await ProcessExecutor.start(shell); var exitCode = await process.process.exitCode; - var ignores = [128/*Already exists*/]; - if(ignores.contains(exitCode)) - { + var ignores = [128 /*Already exists*/]; + if (ignores.contains(exitCode)) { exitCode = 0; } - if(exitCode == 0) - { + if (exitCode == 0) { shell = StringBuffer(getCDPath(workspace)); shell.write(' && git checkout $branch'); - - if(data.executePull == null ? true : data.executePull!) - { + + if (data.executePull == null ? true : data.executePull!) { shell.write(' && git pull origin $branch'); } process = await ProcessExecutor.start(shell); exitCode = await process.process.exitCode; } - + return await completeProcess(process, command); } } @@ -122,7 +117,7 @@ class GitReset extends Command { shell.write(' && git reset --hard'); shell.write(' && git clean -${force}d'); var process = await ProcessExecutor.start(shell, printStderr: false); - + return await completeProcess(process, command); } } @@ -134,11 +129,13 @@ class GitStashPush extends Command { var data = DataGitStashPush.fromJson(getParam(command)); var shell = StringBuffer(getCDPath(workspace)); - var includeUntracked = data.includeUntracked == null ? " -u" : (data.includeUntracked! ? " -u" : ""); + var includeUntracked = data.includeUntracked == null + ? " -u" + : (data.includeUntracked! ? " -u" : ""); var message = data.message == null ? "" : " -m '${data.message}'"; shell.write(' && git stash push$includeUntracked$message'); var process = await ProcessExecutor.start(shell, printStderr: false); - + return await completeProcess(process, command); } } @@ -149,31 +146,41 @@ class GitStashApply extends Command { Future execute(DataCommand command) async { var data = DataGitStashApply.fromJson(getParam(command)); + ProcessData process; var shell = StringBuffer(getCDPath(workspace)); - var apply = data.delete == null ? " pop" : (data.delete! ? " pop" : " apply"); - if(data.message == null) { + var apply = + data.delete == null ? " pop" : (data.delete! ? " pop" : " apply"); + if (data.message == null) { shell.write(' && git stash$apply'); + process = await ProcessExecutor.start(shell, printStderr: false); } else { shell.write(' && git stash list'); var result = await ProcessExecutor.run(shell); + var exist = false; print(result.stdout); shell = StringBuffer(getCDPath(workspace)); - if(result.exitCode == 0) { + if (result.exitCode == 0) { var arr = result.stdout.toString().split('\n'); - for(var line in arr) { + for (var line in arr) { var lineArr = line.split(': On '); - if(lineArr.length > 1) { + if (lineArr.length > 1) { var id = lineArr[0]; var content = lineArr[1]; - if(content.contains(data.message!)) { + if (content.contains(data.message!)) { shell.write(' && git stash$apply $id'); + exist = true; break; } } } } + + if (exist) { + process = await ProcessExecutor.start(shell, printStderr: false); + } else { + return await complete(0, command); + } } - var process = await ProcessExecutor.start(shell, printStderr: false); - return await completeProcess(process, command); + return await completeProcess(process, command, passExitCodes: [1]); } }