-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat][command] implements update-index
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import typer | ||
from typer import Option, Argument | ||
from typing_extensions import Optional, Annotated | ||
|
||
from xgit.types.index import get_index | ||
from xgit.utils.utils import find_repo | ||
|
||
|
||
def update_index( | ||
files: Annotated[Optional[list[str]], Argument(help="要更新的文件")] = None, | ||
add: Annotated[bool, Option("--add", help="如果文件在暂存区中不存在,则加入暂存区")] = False, | ||
remove: Annotated[bool, Option("--remove", help="如果文件在暂存区存在,但在本地不存在,则从暂存区移除")] = False, | ||
force_remove: Annotated[bool, Option("--force-remove", help="从暂存区移除文件,即使文件在本地存在")] = False, | ||
refresh: Annotated[bool, Option("--refresh", help="刷新暂存区中的文件状态")] = False, | ||
verbose: Annotated[bool, Option("-v", help="详细输出添加和删除的文件")] = False, | ||
cacheinfo: Annotated[ | ||
Optional[list[str]], Option("--cacheinfo", help="与 `--add` 一同使用,用 `<mode>,<object>,<path>` 指定一个 blob 加入暂存区") | ||
] = None, | ||
): | ||
""" | ||
更新暂存区 | ||
""" | ||
# === 检查参数正确性 === | ||
# add, remove, force_remove, verbose 互斥 | ||
if add + remove + force_remove + refresh + verbose > 1: | ||
typer.echo("fatal: only one of the options can be used", err=True) | ||
sys.exit(1) | ||
|
||
# refresh 不能与 files 同时使用 | ||
if refresh and files: | ||
typer.echo("fatal: --refresh cannot be used with files", err=True) | ||
sys.exit(1) | ||
|
||
# cacheinfo 必须与 add 同时使用 | ||
if cacheinfo and not add: | ||
typer.echo("fatal: --cacheinfo can only be used with --add", err=True) | ||
sys.exit(1) |