• This repository has been archived on 15/Dec/2022
  • Stars
    star
    167
  • Rank 218,552 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Git Node Module
Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our official announcement

Git Node module CI

Helpers for working with Git repositories built natively on top of libgit2.

Installing

npm install git-utils

Development

  • Clone the repository
  • Run npm run prepare to get the submodule
  • Run npm install
  • Run npm test to run the specs

Docs

git.open(path, [search = true])

Open the repository at the given path. This will return null if the repository at the given path does not exist or cannot be opened.

path - The path from which to try to open a repository search - Set to false if we shouldn't search up in the directory tree

git = require 'git-utils'

repository = git.open('/Users/me/repos/node')

The opened repository will have a submodules property that will be an object of paths mapped to submodule {Repository} objects. The path keys will be relative to the opened repository's working directory.

If search is set to true (the default), all paths up to the filesystem root will be recursively checked to try and find the root directory of a repository. If a search is false, traversing not be performed, and a repository will only be returned if the given path is the root of a repository.

Repository.checkoutHead(path)

Restore the contents of a path in the working directory and index to the version at HEAD. Similar to running git reset HEAD -- <path> and then a git checkout HEAD -- <path>.

path - The string repository-relative path to checkout.

Returns true if the checkout was successful, false otherwise.

Repository.checkoutReference(reference, [create])

Checks out a branch in your repository.

reference - The string reference to checkout create - A Boolean value which, if true creates the new reference if it doesn't exist.

Returns true if the checkout was successful, false otherwise.

Repository.getAheadBehindCount(branch)

Get the number of commits the branch is ahead/behind the remote branch it is tracking. Similar to the commit numbers reported by git status when a remote tracking branch exists.

branch - The branch name to lookup ahead/behind counts for. (default: HEAD)

Returns an object with ahead and behind keys pointing to integer values that will always be >= 0.

Repository.getCommitCount(fromCommit, toCommit)

Get the number of commits between fromCommit and toCommit.

fromCommit - The string commit SHA-1 to start the rev walk at.

toCommit - The string commit SHA-1 to end the rev walk at.

Returns the number of commits between the two, always >= 0.

Repository.getConfigValue(key)

Get the config value of the given key.

key - The string key to retrieve the value for.

Returns the configuration value, may be null.

Repository.setConfigValue(key, value)

Get the config value of the given key.

key - The string key to set in the config.

value - The string value to set in the config for the given key.

Returns true if setting the config value was successful, false otherwise.

Repository.getDiffStats(path)

Get the number of lines added and removed comparing the working directory contents of the given path to the HEAD version of the given path.

path - The string repository-relative path to diff.

Returns an object with added and deleted keys pointing to integer values that always be >= 0.

Repository.getHeadBlob(path)

Get the blob contents of the given path at HEAD. Similar to git show HEAD:<path>.

path - The string repository-relative path.

Returns the string contents of the HEAD version of the path.

Repository.getHead()

Get the reference or SHA-1 that HEAD points to such as refs/heads/master or a full SHA-1 if the repository is in a detached HEAD state.

Returns the string reference name or SHA-1.

Repository.getIndexBlob(path)

Get the blob contents of the given path in the index. Similar to git show :<path>.

path - The string repository-relative path.

Returns the string contents of the index version of the path.

Repository.getLineDiffs(path, text, [options])

Get the line diffs comparing the HEAD version of the given path and the given text.

path - The string repository-relative path.

text - The string text to diff the HEAD contents of the path against.

options - An optional object with the following keys:

  • ignoreSpaceAtEOL - true to ignore changes in whitespace at the end of lines. (ignoreEolWhitespace also works.)
  • ignoreSpaceChange - true to ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.
  • ignoreAllSpace - true to ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.
  • useIndex - true to compare against the index version instead of the HEAD version.

Returns an array of objects that have oldStart, oldLines, newStart, and newLines keys pointing to integer values, may be null if the diff fails.

Repository.getLineDiffDetails(path, text, [options])

Get the line diff details comparing the HEAD version of the given path and the given text.

Takes the same arguments as getLineDiffs.

Returns an array of objects which represent an old or new line in a diff. Every object has oldStart, oldLines, newStart, newLines, oldLineNumber and newLineNumber keys pointing to integer values, and a line key pointing to the respective line content. May be null if the diff fails.

Repository.getMergeBase(commit1, commit2)

Get the merge base of two commits.

commit1 - The string SHA-1 of the first commit.

commit2 - The string SHA-1 of the second commit.

Returns the string SHA-1 of the merge base of commit1 and commit2 or null if there isn't one.

Repository.getPath()

Get the path of the repository.

Returns the string absolute path of the opened repository.

Repository.getReferences()

Gets all the local and remote references.

Returns an object with three keys: heads, remotes, and tags. Each key can be an array of strings containing the reference names.

Repository.getReferenceTarget(ref)

Get the target of the given reference.

ref - The string reference.

Returns the string target of the given reference.

Repository.getShortHead()

Get a possibly shortened version of value returns by getHead(). This will remove leading segments of refs/heads, refs/tags, or refs/remotes and will also shorten the SHA-1 of a detached HEAD to 7 characters.

Returns a string shortened reference name or SHA-1.

Repository.getStatus([path])

Get the status of a single path or all paths in the repository. This will not include ignored paths.

path - An optional repository-relative path to limit the status reporting to.

Returns an integer status number if a path is specified and returns an object with path keys and integer status values if no path is specified.

Repository.getUpstreamBranch([branch])

Get the upstream branch of the given branch.

branch - The branch to find the upstream branch of (default: HEAD)

Returns the string upstream branch reference name.

Repository.getWorkingDirectory()

Get the working directory of the repository.

Returns the string absolute path to the repository's working directory.

Repository.isIgnored(path)

Get the ignored status of a given path.

path - The string repository-relative path.

Returns true if the path is ignored, false otherwise.

Repository.isPathModified(path)

Get the modified status of a given path.

path - The string repository-relative path.

Returns true if the path is modified, false otherwise.

Repository.isPathNew(path)

Get the new status of a given path.

path - The string repository-relative path.

Returns true if the path is new, false otherwise.

Repository.isPathDeleted(path)

Get the deleted status of a given path.

path - The string repository-relative path.

Returns true if the path is deleted, false otherwise.

Repository.isPathStaged(path)

Get the staged status of a given path.

path - The string repository-relative path.

Returns true if the path is staged in the index, false otherwise.

Repository.isStatusIgnored(status)

Check if a status value represents an ignored path.

status - The integer status value.

Returns true if the status is a ignored one, false otherwise.

Repository.isStatusModified(status)

Check if a status value represents a modified path.

status - The integer status value.

Returns true if the status is a modified one, false otherwise.

Repository.isStatusNew(status)

Check if a status value represents a new path.

status - The integer status value.

Returns true if the status is a new one, false otherwise.

Repository.isStatusDeleted(status)

Check if a status value represents a deleted path.

status - The integer status value.

Returns true if the status is a deleted one, false otherwise.

Repository.isStatusStaged(status)

Check if a status value represents a changed that is staged in the index.

status - The integer status value.

Returns true if the status is a staged one, false otherwise.

Repository.isSubmodule(path)

Check if the path is a submodule in the index.

path - The string repository-relative path.

Returns true if the path is a submodule, false otherwise.

Repository.refreshIndex()

Reread the index to update any values that have changed since the last time the index was read.

Repository.relativize(path)

Relativize the given path to the repository's working directory.

path - The string path to relativize.

Returns a repository-relative path if the given path is prefixed with the repository's working directory path.

Repository.isWorkingDirectory(path)

Is the given path the repository's working directory?

It is better to call this method than comparing a path directly against the value of getWorkingDirectory() since this method handles slash normalization on Windows, case insensitive filesystems, and symlinked repositories.

path - The string path to check.

Returns true if the given path is the repository's working directory, false otherwise.

Repository.release()

Release the repository and close all file handles it has open. No other methods can be called on the Repository object once it has been released.

Repository.submoduleForPath(path)

Get the repository for the submodule that the path is located in.

path - The absolute or repository-relative string path.

Returns a Repository or null if the path isn't in a submodule.

Repository.add(path)

Stage the changes in path into the repository's index. Clear any conflict state associated with path.

path - A repository-relative string path.

Raises an Error if the path isn't readable or if another exception occurs.

More Repositories

1

atom

:atom: The hackable text editor
JavaScript
59,608
star
2

teletype

Share your workspace with team members and collaborate on code in real time in Atom
JavaScript
2,402
star
3

vim-mode

Next generation vim support for atom
CoffeeScript
1,722
star
4

node-keytar

Native Password Node Module
C++
1,364
star
5

apm

Atom Package Manager
CoffeeScript
1,263
star
6

markdown-preview

πŸ“ Markdown preview in Atom
JavaScript
1,235
star
7

github

:octocat: Git and GitHub integration for Atom
JavaScript
1,085
star
8

autocomplete-plus

View and insert possible completions in the editor while typing
JavaScript
961
star
9

teletype-crdt

String-wise sequence CRDT powering peer-to-peer collaborative editing in Teletype for Atom.
JavaScript
749
star
10

flight-manual.atom.io

πŸ“– Documentation for Atom, generated by nanoc, hosted by GitHub Pages
SCSS
632
star
11

tree-view

🌳 Explore and open project files in Atom
CoffeeScript
564
star
12

etch

Builds components using a simple and explicit API around virtual-dom
JavaScript
555
star
13

highlights

Syntax highlighter
CoffeeScript
531
star
14

one-dark-syntax

Atom One dark syntax theme
CSS
433
star
15

atom-languageclient

Language Server Protocol support for Atom (the basis of Atom-IDE)
TypeScript
388
star
16

ide-typescript

TypeScript and Javascript language support for Atom-IDE
JavaScript
367
star
17

fuzzaldrin

Fuzzy filtering and string scoring
CoffeeScript
317
star
18

node-spellchecker

SpellChecker Node Module
C++
294
star
19

fuzzy-finder

Find and open files quickly
JavaScript
277
star
20

settings-view

πŸ”§ Edit Atom settings
CoffeeScript
269
star
21

ide-php

PHP language support for Atom-IDE
JavaScript
266
star
22

one-dark-ui

Atom One dark UI theme
CSS
262
star
23

find-and-replace

Find and replace in a single buffer and in the project
JavaScript
244
star
24

ide-java

Java language support for Atom-IDE
JavaScript
229
star
25

electron-link

A module to bundle your electron app into a single file that can be used for V8 snapshots.
JavaScript
214
star
26

teletype-client

Editor-agnostic library managing client interaction for peer-to-peer collaborative editing in Teletype for Atom
JavaScript
213
star
27

spell-check

Spell check Atom package
JavaScript
206
star
28

watcher

Atom Filesystem Watcher
C++
202
star
29

snippets

Atom snippets package
JavaScript
200
star
30

language-javascript

JavaScript language package for Atom
CoffeeScript
196
star
31

language-python

Python package for Atom
CoffeeScript
188
star
32

sort-lines

An Atom package to sort lines of text
JavaScript
174
star
33

symbols-view

Jump to symbols in Atom
JavaScript
164
star
34

welcome

Welcome editor thats shows on first run
JavaScript
158
star
35

atom.io

🌐 A place for feedback on the atom.io website and package API
157
star
36

superstring

Native core components for Atom
JavaScript
151
star
37

text-buffer

Atom's underlying text buffer
JavaScript
146
star
38

bracket-matcher

Jump to brackets
JavaScript
142
star
39

metrics

Help improve Atom by sending usage statistics, exceptions and deprecations to the team.
JavaScript
139
star
40

node-oniguruma

Oniguruma Node Module
JavaScript
121
star
41

language-php

PHP package for Atom
CoffeeScript
120
star
42

teletype-server

Server-side application that facilitates peer discovery for collaborative editing sessions in Teletype
JavaScript
118
star
43

command-palette

Command Palette in Atom
JavaScript
117
star
44

language-c

C support in Atom
CoffeeScript
117
star
45

styleguide

A package to exercise all the UI components.
JavaScript
115
star
46

fs-plus

node's fs module with some helpful additions
CoffeeScript
108
star
47

language-html

HTML package for Atom
CoffeeScript
108
star
48

tabs

Tabs in Atom
CoffeeScript
107
star
49

language-go

Go language package for Atom
CoffeeScript
106
star
50

atom-keymap

Atom's selector-based keymap system
CoffeeScript
103
star
51

atom-dark-ui

The default dark ui theme for Atom
CSS
103
star
52

git-diff

Diff markers in Atom's gutter
JavaScript
102
star
53

eon

Real-Time Conflict-Free Version Control System
102
star
54

language-ruby

Ruby package for Atom
Ruby
102
star
55

status-bar

Status bar for Atom
CoffeeScript
101
star
56

language-gfm

GitHub Flavored Markdown in Atom
CoffeeScript
101
star
57

event-kit

Simple library for implementing and consuming evented APIs
JavaScript
96
star
58

whitespace

Atom whitespace package
JavaScript
94
star
59

node-pathwatcher

Path Watcher Node Module
CoffeeScript
94
star
60

open-on-github

Atom package for opening files on GitHub.com
JavaScript
94
star
61

package-generator

Package to generate new packages
JavaScript
91
star
62

first-mate

TextMate helpers
JavaScript
89
star
63

season

CSON Node Module
CoffeeScript
85
star
64

ci

Build your Atom packages
PowerShell
83
star
65

language-todo

TODO highlighting package for Atom
CoffeeScript
81
star
66

toggle-quotes

An Atom package to toggle between single and double quotes
JavaScript
77
star
67

notifications

User notifications
CoffeeScript
75
star
68

solarized-dark-syntax

Atom syntax theme using the dark Solarized colors
CSS
74
star
69

one-light-ui

Atom One light UI theme
CSS
74
star
70

autocomplete-emojis

autocomplete+ emoji autocompletion
CoffeeScript
74
star
71

autocomplete-css

CSS property name and value completions
CoffeeScript
69
star
72

ascii-art

Convert selected text to ascii art banner
JavaScript
68
star
73

atom-ui

Atom's UI library
CSS
66
star
74

one-light-syntax

Atom One light syntax theme
CSS
64
star
75

autosave

Autosaves buffers when they lose focus
JavaScript
64
star
76

language-sass

Sass package for Atom
CoffeeScript
63
star
77

atom-space-pen-views

Atom SpacePen views that previously lived in core.
CoffeeScript
63
star
78

language-java

Java package for Atom
CoffeeScript
62
star
79

language-csharp

C# language support for Atom
Python
62
star
80

keyboard-layout

Node module to read and observe the current keyboard layout
C++
61
star
81

autocomplete-html

HTML tag and attribute completions
JavaScript
60
star
82

underscore-plus

Underscore with some extensions
CoffeeScript
60
star
83

language-css

CSS package for Atom
CoffeeScript
59
star
84

language-coffee-script

CoffeeScript support in Atom
CoffeeScript
58
star
85

atomdoc

Atom's documentation parser for JavaScript / CoffeeScript
JavaScript
58
star
86

atom-dark-syntax

Atom Dark Syntax theme
CSS
57
star
87

ide-csharp

C# language support for Atom-IDE
JavaScript
56
star
88

theorist

A reactive model toolkit for CoffeeScript
CoffeeScript
51
star
89

language-clojure

Clojure package for Atom
Clojure
49
star
90

bookmarks

Bookmark editor lines in Atom
JavaScript
49
star
91

language-ruby-on-rails

Ruby on Rails package for Atom
CoffeeScript
48
star
92

language-mustache

Mustache package for Atom
CoffeeScript
47
star
93

template-syntax

A template atom syntax theme to build from
Less
46
star
94

autocomplete-snippets

Adds snippets to autocomplete+ suggestions
JavaScript
46
star
95

keybinding-resolver

Shows what a keybinding resolves to
JavaScript
44
star
96

editor-stats

Graph your keyboard activity
CoffeeScript
44
star
97

image-view

View images in an Atom editor
JavaScript
44
star
98

base16-tomorrow-dark-theme

Base16 Theme for Atom
CSS
41
star
99

pr-changelog

Generate a PR changelog between two refs
JavaScript
40
star
100

scandal

Efficient directory scan + search utilities
CoffeeScript
40
star