vscode 致命错误:无效的对象名称wt

eblbsuwk  于 5个月前  发布在  Vscode
关注(0)|答案(2)|浏览(49)

这个问题在所有扩展都被禁用时是否会发生?:是/否

  • VS Code 版本:1.79.2
  • OS 版本:RHEL 8

重现步骤:

  1. 克隆一个带有子模块的仓库
  2. 更改其中一个子模块的提交
  3. 尝试使用“放弃更改”按钮在VSCode中还原更改
    这确实曾经有效,但现在我在Git日志中看到了这个,但什么都没有发生:
2023-06-22 11:51:36.873 [info] > git ls-tree -l wt -- /path/to/the/submodule[1ms]
2023-06-22 11:51:36.873 [info] fatal: Not a valid object name wt
jum4pzuy

jum4pzuy1#

实际上,我认为wt问题与“丢弃更改”按钮无效的事实无关,因为我只是查看子模块更改时才遇到这个错误。按照代码,我不确定它应该如何工作:

这里是它尝试获取文件状态的地方。它从fromGitUri()获取ref,然后通过sanitizeRef()将其发送到getObjectDetails()

async stat(uri: Uri): Promise<FileStat> {
		await this.model.isInitialized;

		const { submoduleOf, path, ref } = fromGitUri(uri);
		const repository = submoduleOf ? this.model.getRepository(submoduleOf) : this.model.getRepository(uri);
		if (!repository) {
			throw FileSystemError.FileNotFound();
		}

		let size = 0;
		try {
			const details = await repository.getObjectDetails(sanitizeRef(ref, path, repository), path);
			size = details.size;
		} catch {
			// noop
		}
		return { type: FileType.File, size: size, mtime: this.mtime, ctime: 0 };
	}

	export function fromGitUri(uri: Uri): GitUriParams {
		return JSON.parse(uri.query);
	}

在我们的案例中,sanitizeRef()没有做任何显著的事情。

function sanitizeRef(ref: string, path: string, repository: Repository): string {
		if (ref === '~') {
			const fileUri = Uri.file(path);
			const uriString = fileUri.toString();
			const [indexStatus] = repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);
			return indexStatus ? '' : 'HEAD';
		}
	
		if (/^~\d$/.test(ref)) {
			return `:${ref[1]}`;
		}
	
		return ref;
	}

getObjectDetails()调用了lstree(treeish)

async getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }> {
			if (!treeish) { // index
				const elements = await this.lsfiles(path);
	
				if (elements.length === 0) {
					throw new GitError({ message: 'Path not known by git', gitErrorCode: GitErrorCodes.UnknownPath });
				}
	
				const { mode, object } = elements[0];
				const catFile = await this.exec(['cat-file', '-s', object]);
				const size = parseInt(catFile.stdout);
	
				return { mode, object, size };
			}
	
			const elements = await this.lstree(treeish, path);
	
			if (elements.length === 0) {
				throw new GitError({ message: 'Path not known by git', gitErrorCode: GitErrorCodes.UnknownPath });
			}
	
			const { mode, object, size } = elements[0];
			return { mode, object, size: parseInt(size) };
		}

这运行了失败的命令,因为treeish"wt"

async lstree(treeish: string, path: string): Promise<LsTreeElement[]> {
			const { stdout } = await this.exec(['ls-tree', '-l', treeish, '--', sanitizePath(path)]);
			return parseLsTree(stdout);
		}

我认为这来自这里:

getResources(resource: Resource): [Uri | undefined, Uri | undefined] {
		for (const submodule of this.repository.submodules) {
			if (path.join(this.repository.root, submodule.path) === resource.resourceUri.fsPath) {
				return [undefined, toGitUri(resource.resourceUri, resource.resourceGroupType === ResourceGroupType.Index ? 'index' : 'wt', { submoduleOf: this.repository.root })];
			}
		}

		return [this.getLeftResource(resource), this.getRightResource(resource)];
	}

// As a mitigation for extensions like ESLint showing warnings and errors
// for git URIs, let's change the file extension of these uris to .git,
// when `replaceFileExtension` is true.
export function toGitUri(uri: Uri, ref: string, options: GitUriOptions = {}): Uri {
	const params: GitUriParams = {
		path: uri.fsPath,
		ref
	};

	if (options.submoduleOf) {
		params.submoduleOf = options.submoduleOf;
	}

	let path = uri.path;

	if (options.replaceFileExtension) {
		path = `${path}.git`;
	} else if (options.submoduleOf) {
		path = `${path}.diff`;
	}

	return uri.with({
		scheme: 'git',
		path,
		query: JSON.stringify(params)
	});
}
eanckbw9

eanckbw92#

VSCode版本:1.88.1
git版本:2.34.1
[info] > git ls-tree -l wt -- /home/***/dev/Rack/dep/Catch2 [0ms]
[info] fatal: Not a valid object name wt
在添加子模块并运行git submodule update --init --recursive后遇到了这个问题

相关问题