Class: RepoGit

Inherits:
Object
  • Object
show all
Defined in:
lib/punt/repo/repo_git.rb

Instance Method Summary collapse

Instance Method Details

#any_uncommited_changes?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
# File 'lib/punt/repo/repo_git.rb', line 3

def any_uncommited_changes?()
    return true if `git diff --numstat | wc -l`.strip != "0"
    return true if `git diff --cached --numstat | wc -l`.strip != "0"
    return true if `git ls-files --others --exclude-standard | wc -l`.strip != "0"
    return false
end

#canonical_revision_name(revision_name, short: false) ⇒ Object



14
15
16
17
# File 'lib/punt/repo/repo_git.rb', line 14

def canonical_revision_name(revision_name, short: false)
    return `git rev-parse --short --verify #{revision_name}`.strip if short
    return `git rev-parse --verify #{revision_name}`.strip
end

#checkout_revision(revision_name, dry_run: false) ⇒ Object



19
20
21
22
# File 'lib/punt/repo/repo_git.rb', line 19

def checkout_revision(revision_name, dry_run: false)
    puts "git checkout #{revision_name}" if dry_run
    `git checkout #{revision_name}` unless dry_run
end

#current_revision_name(short: false) ⇒ Object



10
11
12
# File 'lib/punt/repo/repo_git.rb', line 10

def current_revision_name(short: false)
    canonical_revision_name("HEAD", short: short)
end

#restore_state(state, dry_run: false) ⇒ Object



31
32
33
34
# File 'lib/punt/repo/repo_git.rb', line 31

def restore_state(state, dry_run: false)
    puts "git checkout #{state}" if dry_run
    `git checkout #{state}` unless dry_run
end

#save_stateObject



24
25
26
27
28
29
# File 'lib/punt/repo/repo_git.rb', line 24

def save_state()
    current_branch = `git rev-parse --abbrev-ref HEAD`

    return current_revision_name if current_branch == "HEAD"
    return current_branch
end