文档开发者中心
我的

学习开源项目HiGit

浏览125发布于2026-05-28 10:28山东
HiGit是专为 HarmonyOS 生态打造的移动端 Git 仓库浏览器

让开发者能够在手机或平板上轻量、快速、安全地浏览和管理代码仓库,无需下载完整代码文件。作为开源项目,我们致力于为 HarmonyOS 生态提供最佳的 Git 管理体验。

HiGit-GitHub

我学习了这个开源项目,开发了ArkGit这款App

ArkGit

cke_2547.png

ArkGit让您随时随地管理您的代码仓库。ArkGit 是一款专为 HarmonyOS 设计的原生 Git 客户端,融合了 ArkTS 的简洁与 C++ NAPI 的强大性能。只需轻点几下,即可掌握完整的提交历史。Git 体验从未如此丝滑。

我还借助还没hm_code_editor将编辑器也加上,方便大家在移动端编代码

cke_10863.png

学习的过程中,其实主要是 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等方法,大家可以集成到自己项目里,有任何问题,在评论区讨论哦

收藏
1
回复
1
分享
全部评论
authorIcon
lorin
66666
回复于2026-05-29 00:29广东
写评论
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。
发表
我要写文章
了解社区公约,与您携手共创和谐专业的开发者社区。