File: git.coffee

Defined in: lib/resin/vcs/git

Method Summary

Method Details

~ (String) getGitDirectory(directory) Private

Note: This function doesn't check if the path is valid, it only constructs it.

Get git directory for a certain path

By git directory, we mean the hidden .git folder that every git repository have

result = getGitDirectory('/opt/projects/myapp')
console.log(result)
# /opt/projects/myapp/.git

Parameters:

  • directory ( String ) the directory path

Throws:

  • ( Error ) — Will throw if directory is not a string

Returns:

  • ( String ) — the absolute path to the child .git directory

~ (String) getCurrentGitDirectory() Private

Note: The current directory is determined by from where you ran the app

Get current git directory

Get the path to the .git directory in the current directory

$ cd /Users/me/Projects/foobar && resin ...
result = getCurrentGitDirectory()
console.log(result)
# /Users/me/Projects/foobar/.git

Returns:

  • ( String ) — the absolute path to the current directory's .git folder

~ (void) isGitRepository(directory, callback) Private

Check if a directory is a git repository

isGitRepository 'my/git/repo', (error, isGitRepository) ->    throw error if error?    if isGitRepository
        console.log('Yes, it\'s a git repo!')    else
        console.log('I should use git here!')

Parameters:

  • directory ( String ) the directory
  • callback ( Function ) callback(error, isGitRepository)

Throws:

~ (void) getRepositoryInstance(directory, callback) Private

Get repository instance

An instance of a gitCli repository, for internal usage.

getRepositoryInstance 'my/git/repo', (error, repository) ->    throw error if error?    # I can now use gitCli functions on `repository`

Parameters:

  • directory ( String ) the directory
  • callback ( Function ) callback(error, repository)

Throws:

  • ( Error ) — Will throw if directory is not a git repository.

~ (Boolean) isValidGitApplication(application) Private

TODO: We should also test that the string contained in git_repository is a valid url.
Note: All it does is check if the application object contains a valid git_repository field.

Check if an application is a git app

resin.models.application.get 91, (error, application) ->    throw error if error?    result = isValidGitApplication(application)    console.log(result)    # True

Parameters:

  • application ( Object ) an application from resin API

Returns:

  • ( Boolean ) — wheter is a valid git application or not

~ (void) hasRemote(repository, name, callback) Private

TODO: We should extract the logic that lists all remotes into a separate function.

Check if a repository has a certain remote

repository = getRepositoryInstance('my/git/repo')
hasRemote repository, 'origin', (error, hasRemote) ->    throw error if error?    if hasRemote
        console.log('It has an origin remote!')    else
        console.log('It doesn\'t has an origin remote!')

Parameters:

  • repository ( Object ) a repository instance from getRepositoryInstance()
  • name ( String ) the name of the remote to check for
  • callback ( Function ) callback(error, hasRemote)

~ (void) addRemote(repository, name, url, callback) Private

TODO: We should check the validity of all arguments.
TODO: This function should be better tested

Add a remote to a git repository

repository = getRepositoryInstance('my/git/repo')
addRemote repository, 'resin', 'git@git.resin.io:johndoe/app.git', (error) ->    throw error if error?

$ cd my/git/repo && git remote -v
resin    git@git.resin.io:johndoe/app.git (fetch)
resin    git@git.resin.io:johndoe/app.git (push)

Parameters:

  • repository ( Object ) a repository instance from getRepositoryInstance()
  • name ( String ) the name of the remote to add
  • url ( String ) url of the new remote
  • callback ( Function ) callback(error)

Throws:

  • ( Error ) — Will throw if name is not a string

~ (void) initProjectWithApplication(application, directory, callback)

TODO: This function should be better tested
Note: The directory should already be a git repo (maybe we should take care of git init as well here if necessary?)

Initialize an application project

  • Add the corresponding git remote.
resin.models.application.get 91, (error, application) ->    throw error if error?
initProjectWithApplication application, 'my/new/project', (error) ->
        throw error if error?

Parameters:

  • application ( Object ) an application from resin API
  • directory ( String ) the directory to initialize
  • callback ( Function ) callback(error)

Throws:

  • ( Error ) — Will throw if application is not a valid application

~ (void) isResinProject(directory, callback)

TODO: Find a way to test this function

Check if an application was already initialized

It checks if we have a resin remote added already.

isResinProject 'my/resin/app', (error, initialized) ->    if initialized
        console.log('It\'s already a resin app!')    else
        console.log('It\'s just a boring project! It should be resinified!')

Parameters:

  • directory ( String ) the directory
  • callback ( Function ) callback(error, isResinProject)

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: