Method: Rugged::Repository#exists?

Defined in:
ext/rugged/rugged_repo.c

#include?(oid) ⇒ Boolean #exists?(oid) ⇒ Boolean

Return whether an object with the given SHA1 OID (represented as a hex string of at least 7 characters) exists in the repository.

repo.include?("d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f") #=> true
repo.include?("d8786bfc") #=> true

Overloads:

  • #include?(oid) ⇒ Boolean

    Returns:

    • (Boolean)
  • #exists?(oid) ⇒ Boolean

    Returns:

    • (Boolean)
[View source]

1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
# File 'ext/rugged/rugged_repo.c', line 1120

static VALUE rb_git_repo_exists(VALUE self, VALUE hex)
{
	git_repository *repo;
	git_odb *odb;
	git_oid oid;
	int error;

	Data_Get_Struct(self, git_repository, repo);
	Check_Type(hex, T_STRING);

	error = git_oid_fromstrn(&oid, RSTRING_PTR(hex), RSTRING_LEN(hex));
	rugged_exception_check(error);

	error = git_repository_odb(&odb, repo);
	rugged_exception_check(error);

	error = git_odb_exists_prefix(NULL, odb, &oid, RSTRING_LEN(hex));
	git_odb_free(odb);

	if (error == 0 || error == GIT_EAMBIGUOUS)
		return Qtrue;

	return Qfalse;
}