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
Afficher le fichier Open project: stschake/GitSharp Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

Close all resources used by this repository
public Close ( ) : void
Résultat void

Create() public méthode

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

Create() public méthode

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.
Résultat void

Dispose() public méthode

public Dispose ( ) : void
Résultat void

HasObject() public méthode

public HasObject ( AnyObjectId objectId ) : bool
objectId AnyObjectId
Résultat bool

IncrementOpen() public méthode

public IncrementOpen ( ) : void
Résultat void

IsValidRefName() public static méthode

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
Résultat bool

Link() public méthode

public Link ( string name, string target ) : void
name string
target string
Résultat void

MapCommit() public méthode

Access a Commit by SHA'1 id.
public MapCommit ( ObjectId id ) : Commit
id ObjectId
Résultat Commit

MapCommit() public méthode

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
Résultat Commit

MapObject() public méthode

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
Résultat object

MapTag() public méthode

Access a tag by symbolic name.
public MapTag ( string revstr ) : Tag
revstr string
Résultat Tag

MapTag() public méthode

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

MapTree() public méthode

Access a Tree by SHA'1 id.
public MapTree ( ObjectId id ) : Tree
id ObjectId
Résultat Tree

MapTree() public méthode

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
Résultat Tree

Open() public static méthode

public static Open ( DirectoryInfo directory ) : Repository
directory DirectoryInfo
Résultat Repository

Open() public static méthode

public static Open ( string directory ) : Repository
directory string
Résultat Repository

OpenBlob() public méthode

public OpenBlob ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a blob
Résultat ObjectLoader

OpenCommit() public méthode

public OpenCommit ( ObjectId id ) : Commit
id ObjectId
Résultat Commit

OpenObject() public méthode

public OpenObject ( AnyObjectId id ) : ObjectLoader
id AnyObjectId SHA-1 of an object.
Résultat ObjectLoader

OpenObject() public méthode

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

OpenObjectInAllPacks() public méthode

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. ///
Résultat IEnumerable

OpenObjectInAllPacks() public méthode

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. ///
Résultat void

OpenPack() public méthode

public OpenPack ( FileInfo pack, FileInfo idx ) : void
pack FileInfo
idx FileInfo
Résultat void

OpenTree() public méthode

public OpenTree ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a tree
Résultat ObjectLoader

Peel() public méthode

public Peel ( Ref pRef ) : Ref
pRef Ref
Résultat Ref

ReflogReader() public méthode

The could not be accessed.
public ReflogReader ( string refName ) : ReflogReader
refName string
Résultat ReflogReader

RefreshFromDisk() public méthode

Clean up stale caches.
public RefreshFromDisk ( ) : void
Résultat void

RenameRef() public méthode

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.
Résultat RefRename

Repository() public méthode

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).
Résultat System

Repository() public méthode

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.
Résultat System

Repository() public méthode

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.
Résultat System

Resolve() public méthode

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.
Résultat ObjectId

ShortenRefName() public static méthode

public static ShortenRefName ( string refName ) : string
refName string
Résultat string

StripWorkDir() public static méthode

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
Résultat string

ToFile() public méthode

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
Résultat FileInfo

ToString() public méthode

public ToString ( ) : string
Résultat string

UpdateRef() public méthode

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. ///
Résultat RefUpdate

UpdateRef() public méthode

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
Résultat RefUpdate

WriteSymref() public méthode

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

addAnyRepositoryChangedListener() public static méthode

public static addAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Résultat void

addRepositoryChangedListener() public méthode

public addRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Résultat void

getAllRefs() public méthode

public getAllRefs ( ) : Ref>.Dictionary
Résultat Ref>.Dictionary

getAllRefsByPeeledObjectId() public méthode

public getAllRefsByPeeledObjectId ( ) : List>.Dictionary
Résultat List>.Dictionary

getBranch() public méthode

public getBranch ( ) : string
Résultat string

getIndexFile() public méthode

public getIndexFile ( ) : FileInfo
Résultat FileInfo

getRef() public méthode

public getRef ( string name ) : Ref
name string
Résultat Ref

getTags() public méthode

public getTags ( ) : Ref>.Dictionary
Résultat Ref>.Dictionary

removeAnyRepositoryChangedListener() public static méthode

public static removeAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Résultat void

removeRepositoryChangedListener() public méthode

public removeRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Résultat void

scanForRepoChanges() public méthode

public scanForRepoChanges ( ) : void
Résultat void

setWorkDir() public méthode

Override default workdir
public setWorkDir ( DirectoryInfo workTree ) : void
workTree DirectoryInfo the work tree directory
Résultat void