C# Class GitSharp.Core.Repository

Represents a Git repository. A repository holds all objects and refs used for managing source code (could by any type of file, but source code is what SCM's are typically used for). In Git terms all data is stored in GIT_DIR, typically a directory called .git. A work tree is maintained unless the repository is a bare repository. Typically the .git directory is located at the root of the work dir.
  • GIT_DIR
    • objects/ - objects
    • refs/ - tags and heads
    • config - configuration
    • info/ - more configurations
This class is thread-safe. This implementation only handles a subtly undocumented subset of git features.
Inheritance: IDisposable
Mostrar archivo Open project: stschake/GitSharp Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Close all resources used by this repository

Create ( ) : void

Create a new Git repository initializing the necessary files and directories.

Create ( bool bare ) : void

Create a new Git repository initializing the necessary files and directories.

Dispose ( ) : void
HasObject ( AnyObjectId objectId ) : bool

IncrementOpen ( ) : void
IsValidRefName ( string refName ) : bool

Check validity of a ref name. It must not contain character that has a special meaning in a Git object reference expression. Some other dangerous characters are also excluded.

Link ( string name, string target ) : void
MapCommit ( ObjectId id ) : Commit

Access a Commit by SHA'1 id.

MapCommit ( string resolveString ) : Commit

Access a Commit object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^ etc.

MapObject ( ObjectId id, string refName ) : object

Access any type of Git object by id and

MapTag ( string revstr ) : Tag

Access a tag by symbolic name.

MapTag ( string refName, ObjectId id ) : Tag

Access a Tag by SHA'1 id

MapTree ( ObjectId id ) : Tree

Access a Tree by SHA'1 id.

MapTree ( string revstr ) : Tree

Access a Tree object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^{tree} etc.

Open ( DirectoryInfo directory ) : Repository
Open ( string directory ) : Repository
OpenBlob ( ObjectId id ) : ObjectLoader

OpenCommit ( ObjectId id ) : Commit
OpenObject ( AnyObjectId id ) : ObjectLoader

OpenObject ( WindowCursor windowCursor, AnyObjectId id ) : ObjectLoader

OpenObjectInAllPacks ( AnyObjectId objectId, WindowCursor windowCursor ) : IEnumerable

Open object in all packs containing specified object.

OpenObjectInAllPacks ( AnyObjectId objectId, ICollection resultLoaders, WindowCursor windowCursor ) : void

Open object in all packs containing specified object.

OpenPack ( FileInfo pack, FileInfo idx ) : void
OpenTree ( ObjectId id ) : ObjectLoader

Peel ( Ref pRef ) : Ref
ReflogReader ( string refName ) : ReflogReader

RefreshFromDisk ( ) : void

Clean up stale caches.

RenameRef ( string fromRef, string toRef ) : RefRename

Create a command to rename a ref in this repository

Repository ( DirectoryInfo d ) : System

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.

Repository ( DirectoryInfo d, DirectoryInfo workTree ) : System

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.

Repository ( DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir, DirectoryInfo alternateObjectDir, FileInfo indexFile ) : System

Construct a representation of a Git repository using the given parameters possibly overriding default conventions..

Resolve ( string revision ) : ObjectId

Parse a git revision string and return an object id. Currently supported is combinations of these.

  • SHA-1 - a SHA-1
  • refs/... - a ref name
  • ref^n - nth parent reference
  • ref~n - distance via parent reference
  • ref@{n} - nth version of ref
  • ref^{tree} - tree references by ref
  • ref^{commit} - commit references by ref
Not supported is
  • timestamps in reflogs, ref@{full or relative timestamp}
  • abbreviated SHA-1's

ShortenRefName ( string refName ) : string

StripWorkDir ( FileSystemInfo workDir, FileSystemInfo file ) : string

Strip work dir and return normalized repository path

ToFile ( AnyObjectId objectId ) : FileInfo

Construct a filename where the loose object having a specified SHA-1 should be stored. If the object is stored in a shared repository the path to the alternative repo will be returned. If the object is not yet store a usable path in this repo will be returned. It is assumed that callers will look for objects in a pack first.

ToString ( ) : string
UpdateRef ( string refName ) : RefUpdate

Create a command to update (or create) a ref in this repository.

UpdateRef ( string refName, bool detach ) : RefUpdate

Create a command to update, create or delete a ref in this repository.

WriteSymref ( string name, string target ) : void

Writes a symref (e.g. HEAD) to disk

addAnyRepositoryChangedListener ( RepositoryListener l ) : void
addRepositoryChangedListener ( RepositoryListener l ) : void
getAllRefs ( ) : Ref>.Dictionary
getAllRefsByPeeledObjectId ( ) : List>.Dictionary
getBranch ( ) : string
getIndexFile ( ) : FileInfo
getRef ( string name ) : Ref
getTags ( ) : Ref>.Dictionary
removeAnyRepositoryChangedListener ( RepositoryListener l ) : void
removeRepositoryChangedListener ( RepositoryListener l ) : void
scanForRepoChanges ( ) : void
setWorkDir ( DirectoryInfo workTree ) : void

Override default workdir

Private Methods

Method Description
GitInternalSlash ( byte bytes ) : byte[]

Replaces any windows director separators (backslash) with /

MakeCommit ( ObjectId id, byte raw ) : object
MakeTag ( ObjectId id, string refName, byte raw ) : Tag
MakeTree ( ObjectId id, byte raw ) : Tree
ResolveSimple ( string revstr ) : ObjectId
fireIndexChanged ( ) : void
fireRefsMaybeChanged ( ) : void

Method Details

Close() public method

Close all resources used by this repository
public Close ( ) : void
return void

Create() public method

Create a new Git repository initializing the necessary files and directories.
public Create ( ) : void
return void

Create() public method

Create a new Git repository initializing the necessary files and directories.
public Create ( bool bare ) : void
bare bool if true, a bare repository is created.
return void

Dispose() public method

public Dispose ( ) : void
return void

HasObject() public method

public HasObject ( AnyObjectId objectId ) : bool
objectId AnyObjectId
return bool

IncrementOpen() public method

public IncrementOpen ( ) : void
return void

IsValidRefName() public static method

Check validity of a ref name. It must not contain character that has a special meaning in a Git object reference expression. Some other dangerous characters are also excluded.
public static IsValidRefName ( string refName ) : bool
refName string
return bool

Link() public method

public Link ( string name, string target ) : void
name string
target string
return void

MapCommit() public method

Access a Commit by SHA'1 id.
public MapCommit ( ObjectId id ) : Commit
id ObjectId
return Commit

MapCommit() public method

Access a Commit object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^ etc.
public MapCommit ( string resolveString ) : Commit
resolveString string a reference to a git commit object
return Commit

MapObject() public method

Access any type of Git object by id and
public MapObject ( ObjectId id, string refName ) : object
id ObjectId SHA-1 of object to read
refName string optional, only relevant for simple tags
return object

MapTag() public method

Access a tag by symbolic name.
public MapTag ( string revstr ) : Tag
revstr string
return Tag

MapTag() public method

Access a Tag by SHA'1 id
public MapTag ( string refName, ObjectId id ) : Tag
refName string
id ObjectId
return Tag

MapTree() public method

Access a Tree by SHA'1 id.
public MapTree ( ObjectId id ) : Tree
id ObjectId
return Tree

MapTree() public method

Access a Tree object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^{tree} etc.
public MapTree ( string revstr ) : Tree
revstr string a reference to a git commit object
return Tree

Open() public static method

public static Open ( DirectoryInfo directory ) : Repository
directory DirectoryInfo
return Repository

Open() public static method

public static Open ( string directory ) : Repository
directory string
return Repository

OpenBlob() public method

public OpenBlob ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a blob
return ObjectLoader

OpenCommit() public method

public OpenCommit ( ObjectId id ) : Commit
id ObjectId
return Commit

OpenObject() public method

public OpenObject ( AnyObjectId id ) : ObjectLoader
id AnyObjectId SHA-1 of an object.
return ObjectLoader

OpenObject() public method

public OpenObject ( WindowCursor windowCursor, AnyObjectId id ) : ObjectLoader
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
id AnyObjectId SHA-1 of an object.
return ObjectLoader

OpenObjectInAllPacks() public method

Open object in all packs containing specified object.
public OpenObjectInAllPacks ( AnyObjectId objectId, WindowCursor windowCursor ) : IEnumerable
objectId AnyObjectId id of object to search for
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
return IEnumerable

OpenObjectInAllPacks() public method

Open object in all packs containing specified object.
public OpenObjectInAllPacks ( AnyObjectId objectId, ICollection resultLoaders, WindowCursor windowCursor ) : void
objectId AnyObjectId of object to search for
resultLoaders ICollection /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object ///
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
return void

OpenPack() public method

public OpenPack ( FileInfo pack, FileInfo idx ) : void
pack FileInfo
idx FileInfo
return void

OpenTree() public method

public OpenTree ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a tree
return ObjectLoader

Peel() public method

public Peel ( Ref pRef ) : Ref
pRef Ref
return Ref

ReflogReader() public method

The could not be accessed.
public ReflogReader ( string refName ) : ReflogReader
refName string
return ReflogReader

RefreshFromDisk() public method

Clean up stale caches.
public RefreshFromDisk ( ) : void
return void

RenameRef() public method

Create a command to rename a ref in this repository
The rename could not be performed.
public RenameRef ( string fromRef, string toRef ) : RefRename
fromRef string Name of ref to rename from.
toRef string Name of ref to rename to.
return RefRename

Repository() public method

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.
public Repository ( DirectoryInfo d ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata).
return System

Repository() public method

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.
public Repository ( DirectoryInfo d, DirectoryInfo workTree ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata).
workTree DirectoryInfo GIT_WORK_TREE (the root of the checkout). May be null for default value.
return System

Repository() public method

Construct a representation of a Git repository using the given parameters possibly overriding default conventions..
public Repository ( DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir, DirectoryInfo alternateObjectDir, FileInfo indexFile ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata). May be null for default value in which case it depends on GIT_WORK_TREE.
workTree DirectoryInfo GIT_WORK_TREE (the root of the checkout). May be null for default value if GIT_DIR is
objectDir DirectoryInfo GIT_OBJECT_DIRECTORY (where objects and are stored). May be null for default value. Relative names ares resolved against GIT_WORK_TREE
alternateObjectDir DirectoryInfo GIT_ALTERNATE_OBJECT_DIRECTORIES (where more objects are read from). May be null for default value. Relative names ares resolved against GIT_WORK_TREE
indexFile FileInfo GIT_INDEX_FILE (the location of the index file). May be null for default value. Relative names ares resolved against GIT_WORK_TREE.
return System

Resolve() public method

Parse a git revision string and return an object id. Currently supported is combinations of these.
  • SHA-1 - a SHA-1
  • refs/... - a ref name
  • ref^n - nth parent reference
  • ref~n - distance via parent reference
  • ref@{n} - nth version of ref
  • ref^{tree} - tree references by ref
  • ref^{commit} - commit references by ref
Not supported is
  • timestamps in reflogs, ref@{full or relative timestamp}
  • abbreviated SHA-1's
On serious errors.
public Resolve ( string revision ) : ObjectId
revision string A git object references expression.
return ObjectId

ShortenRefName() public static method

public static ShortenRefName ( string refName ) : string
refName string
return string

StripWorkDir() public static method

Strip work dir and return normalized repository path
public static StripWorkDir ( FileSystemInfo workDir, FileSystemInfo file ) : string
workDir FileSystemInfo Work directory
file FileSystemInfo File whose path shall be stripp off it's workdir
return string

ToFile() public method

Construct a filename where the loose object having a specified SHA-1 should be stored. If the object is stored in a shared repository the path to the alternative repo will be returned. If the object is not yet store a usable path in this repo will be returned. It is assumed that callers will look for objects in a pack first.
public ToFile ( AnyObjectId objectId ) : FileInfo
objectId AnyObjectId
return FileInfo

ToString() public method

public ToString ( ) : string
return string

UpdateRef() public method

Create a command to update (or create) a ref in this repository.
public UpdateRef ( string refName ) : RefUpdate
refName string /// name of the ref the caller wants to modify. ///
return RefUpdate

UpdateRef() public method

Create a command to update, create or delete a ref in this repository.
public UpdateRef ( string refName, bool detach ) : RefUpdate
refName string name of the ref the caller wants to modify.
detach bool true to create a detached head
return RefUpdate

WriteSymref() public method

Writes a symref (e.g. HEAD) to disk
public WriteSymref ( string name, string target ) : void
name string symref name
target string pointed to ref
return void

addAnyRepositoryChangedListener() public static method

public static addAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
return void

addRepositoryChangedListener() public method

public addRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
return void

getAllRefs() public method

public getAllRefs ( ) : Ref>.Dictionary
return Ref>.Dictionary

getAllRefsByPeeledObjectId() public method

public getAllRefsByPeeledObjectId ( ) : List>.Dictionary
return List>.Dictionary

getBranch() public method

public getBranch ( ) : string
return string

getIndexFile() public method

public getIndexFile ( ) : FileInfo
return FileInfo

getRef() public method

public getRef ( string name ) : Ref
name string
return Ref

getTags() public method

public getTags ( ) : Ref>.Dictionary
return Ref>.Dictionary

removeAnyRepositoryChangedListener() public static method

public static removeAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
return void

removeRepositoryChangedListener() public method

public removeRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
return void

scanForRepoChanges() public method

public scanForRepoChanges ( ) : void
return void

setWorkDir() public method

Override default workdir
public setWorkDir ( DirectoryInfo workTree ) : void
workTree DirectoryInfo the work tree directory
return void