HiGit是专为 HarmonyOS 生态打造的移动端 Git 仓库浏览器
让开发者能够在手机或平板上轻量、快速、安全地浏览和管理代码仓库,无需下载完整代码文件。作为开源项目,我们致力于为 HarmonyOS 生态提供最佳的 Git 管理体验。
我学习了这个开源项目,开发了ArkGit这款App

ArkGit让您随时随地管理您的代码仓库。ArkGit 是一款专为 HarmonyOS 设计的原生 Git 客户端,融合了 ArkTS 的简洁与 C++ NAPI 的强大性能。只需轻点几下,即可掌握完整的提交历史。Git 体验从未如此丝滑。
我还借助还没hm_code_editor将编辑器也加上,方便大家在移动端编代码

学习的过程中,其实主要是 C++ NAPI 的调用
我写了一个工具类,将调用封装的方法
import nativeApi from 'libentry.so';
import { NativeResult, Result } from '../data/Result';
export async function initGit(path: string): Promise<void> {
nativeApi.initSystem(path);
}
@Concurrent
export async function getSSHKey(): Promise<string> {
const result = nativeApi.getSSHKey();
return result.data;
}
@Concurrent
export async function generateSSHKey(): Promise<Result> {
const result = nativeApi.generateSSHKey();
return Result.fromNative(result);
}
@Concurrent
export async function initRepo(path: string, url: string, repo: string, provider: string): Promise<Result> {
const result = nativeApi.initRepo(path, url, repo, provider);
return Result.fromNative(result);
}
export function setRepoCredential(url: string, username: string, password: string): Result {
const result = nativeApi.setRepoCredential(url, username, password);
return Result.fromNative(result);
}
export function setCloneProgressCallback(callback: (process: number, total: number, message: string) => void): Result {
const result = nativeApi.setCloneProgressCallback(callback);
return Result.fromNative(result);
}
export async function cloneRepo(path: string, url: string, repo: string, provider: string): Promise<Result> {
const result: NativeResult = await nativeApi.cloneRepo(path, url, repo, provider);
return Result.fromNative(result);
}
@Concurrent
export async function getFileTree(url: string, branch: string): Promise<Result> {
const result = nativeApi.getFileTree(url, branch);
return Result.fromNative(result);
}
@Concurrent
export async function readFile(url: string, branch: string, path: string): Promise<Result> {
const result = nativeApi.readFile(url, branch, path);
return Result.fromNative(result);
}
@Concurrent
export async function exportFile(url: string, branch: string, path: string, destPath: string): Promise<Result> {
const result = nativeApi.exportFile(url, branch, path, destPath);
return Result.fromNative(result);
}
@Concurrent
export async function getStatus(url: string): Promise<Result> {
const result = nativeApi.getStatus(url);
return Result.fromNative(result);
}
@Concurrent
export async function getHistory(url: string, branch: string, count: number, offset: number): Promise<Result> {
const result = nativeApi.history(url, branch, count, offset);
return Result.fromNative(result);
}
@Concurrent
export async function getCommitDetail(url: string, commitId: string): Promise<Result> {
const result = nativeApi.getCommitDetail(url, commitId);
return Result.fromNative(result);
}
@Concurrent
export async function getBranches(url: string): Promise<Result> {
const result = nativeApi.getBranches(url);
return Result.fromNative(result);
}
@Concurrent
export async function getTags(url: string): Promise<Result> {
const result = nativeApi.getTags(url);
return Result.fromNative(result);
}
@Concurrent
export async function stageAll(url: string): Promise<Result> {
const result = nativeApi.stageAll(url);
return Result.fromNative(result);
}
@Concurrent
export async function unstageAll(url: string): Promise<Result> {
const result = nativeApi.unstageAll(url);
return Result.fromNative(result);
}
@Concurrent
export async function discardAll(url: string): Promise<Result> {
const result = nativeApi.discardAll(url);
return Result.fromNative(result);
}
@Concurrent
export async function commit(url: string, message: string): Promise<Result> {
const result = nativeApi.commit(url, message);
return Result.fromNative(result);
}
@Concurrent
export async function createTag(url: string, tagName: string, pushToRemote: boolean): Promise<Result> {
const result = nativeApi.createTag(url, tagName, pushToRemote);
return Result.fromNative(result);
}
@Concurrent
export async function push(url: string, branch: string): Promise<Result> {
const result = nativeApi.push(url, branch);
return Result.fromNative(result);
}
@Concurrent
export async function pull(url: string, branch: string): Promise<Result> {
const result = nativeApi.pull(url, branch);
return Result.fromNative(result);
}
@Concurrent
export async function checkout(url: string, branch: string): Promise<Result> {
const result: NativeResult = nativeApi.checkout(url, branch);
return Result.fromNative(result);
}
@Concurrent
export async function cherryPick(url: string, commitId: string): Promise<Result> {
const result = nativeApi.cherryPick(url, commitId);
return Result.fromNative(result);
}
@Concurrent
export async function deleteRepo(path: string, url: string, repo: string, provider: string): Promise<Result> {
const result = nativeApi.deleteRepo(path, url, repo, provider);
return Result.fromNative(result);
}包含了stage、checkout、clone、commit、push等方法,大家可以集成到自己项目里,有任何问题,在评论区讨论哦









































苏公安网备 32011402010933号