From 88af0e5a8555ee4805dc729cc90c8da5c36b0040 Mon Sep 17 00:00:00 2001 From: leedongmyung Date: Tue, 26 Nov 2024 09:02:14 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B9=83=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EC=BB=A4=EB=A9=98=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/oto/commands/command.dart | 9 ++++++++- lib/oto/commands/git/git.dart | 16 ++++++++++++++++ lib/oto/data/command_data.dart | 15 +++++++++++++++ lib/oto/data/command_data.g.dart | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/oto/commands/command.dart b/lib/oto/commands/command.dart index fb2771d..51c06fa 100644 --- a/lib/oto/commands/command.dart +++ b/lib/oto/commands/command.dart @@ -80,6 +80,7 @@ enum CommandType { GitCheckout, GitRev, GitCount, + GitReset, GitHub, GitHubPullRequestCreate, GitHubPullRequestList, @@ -137,6 +138,7 @@ abstract class Command { CommandType.GitCheckout: () => GitCheckout(), CommandType.GitRev: () => GitRev(), CommandType.GitCount: () => GitCount(), + CommandType.GitReset: () => GitReset(), CommandType.GitHub: () => GitHub(), CommandType.GitHubPullRequestCreate: () => GitHubPullRequestCreate(), CommandType.GitHubPullRequestList: () => GitHubPullRequestList(), @@ -360,7 +362,12 @@ abstract class Command { } Map getParam(DataCommand command) { - var map = Command.replaceAllTagsMap(command.param); + Map map; + if(command.param == null) { + map = {}; + } else { + map = Command.replaceAllTagsMap(command.param); + } map['workspace'] = _workspace = getWorkspace(map['workspace']); return map; } diff --git a/lib/oto/commands/git/git.dart b/lib/oto/commands/git/git.dart index 1d8148b..7acaac7 100644 --- a/lib/oto/commands/git/git.dart +++ b/lib/oto/commands/git/git.dart @@ -110,3 +110,19 @@ class GitRev extends Command { return await completeProcess(process, command); } } + +//git 초기화 +class GitReset extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitReset.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + var force = data.force! ? 'f' : ''; + shell.write(' && git reset --hard'); + shell.write(' && git clean -${force}d'); + var process = await ProcessExecutor.start(shell, printStderr: false); + + return await completeProcess(process, command); + } +} diff --git a/lib/oto/data/command_data.dart b/lib/oto/data/command_data.dart index acc7b37..a49d3f0 100644 --- a/lib/oto/data/command_data.dart +++ b/lib/oto/data/command_data.dart @@ -1,5 +1,7 @@ // ignore_for_file: non_constant_identifier_names, avoid_init_to_null +import 'dart:ffi'; + import 'package:dart_framework/utils/slack/slack_sender.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:dart_framework/core/app_data_manager.dart'; @@ -619,6 +621,19 @@ class DataGitRev extends DataParam { Map toJson() => _$DataGitRevToJson(this); } +//GitReset +@JsonSerializable() +class DataGitReset extends DataParam { + DataGitReset(); + + late bool? force = true; + + factory DataGitReset.fromJson(Map json) => + _$DataGitResetFromJson(json); + @override + Map toJson() => _$DataGitResetToJson(this); +} + //GitHub @JsonSerializable() class DataGitHub extends DataParam { diff --git a/lib/oto/data/command_data.g.dart b/lib/oto/data/command_data.g.dart index 8be6f47..500b5c3 100644 --- a/lib/oto/data/command_data.g.dart +++ b/lib/oto/data/command_data.g.dart @@ -72,6 +72,7 @@ const _$CommandTypeEnumMap = { CommandType.GitCheckout: 'GitCheckout', CommandType.GitRev: 'GitRev', CommandType.GitCount: 'GitCount', + CommandType.GitReset: 'GitReset', CommandType.GitHub: 'GitHub', CommandType.GitHubPullRequestCreate: 'GitHubPullRequestCreate', CommandType.GitHubPullRequestList: 'GitHubPullRequestList', @@ -996,6 +997,24 @@ Map _$DataGitRevToJson(DataGitRev instance) => 'setValue': instance.setValue, }; +DataGitReset _$DataGitResetFromJson(Map json) => DataGitReset() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => (e as num).toInt()) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..force = json['force'] as bool?; + +Map _$DataGitResetToJson(DataGitReset instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'force': instance.force, + }; + DataGitHub _$DataGitHubFromJson(Map json) => DataGitHub() ..workspace = json['workspace'] as String? ..passExitCodes = (json['passExitCodes'] as List?)