Skip to content

Instantly share code, notes, and snippets.

@jwliechty
Last active October 21, 2015 15:59
Show Gist options
  • Select an option

  • Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.

Select an option

Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.

Revisions

  1. jwliechty renamed this gist Oct 21, 2015. 1 changed file with 15 additions and 16 deletions.
    31 changes: 15 additions & 16 deletions gitHelp.sh → git_library.sh
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,38 @@
    #!/bin/bash -e

    # Library methods for git operations
    # See http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git

    runTest(){
    if hasStagedChanges; then
    git::run_test(){
    if git::has_staged_changes; then
    echo "There are staged changes"
    fi
    if hasWorkingChanges; then
    if git::has_working_changes; then
    echo "There are working changes"
    fi
    if hasUntrackedChanges; then
    if git::has_untracked_changes; then
    echo "There are untracked changes"
    fi
    if hasAnyChanges; then
    if git::has_any_changes; then
    echo 'Repo is dirty!'
    fi
    }

    hasAnyChanges(){
    hasStagedChanges || hasWorkingChanges || hasUntrackedChanges
    git::has_any_changes(){
    git::has_staged_changes \
    || git::has_working_changes \
    || git::has_untracked_changes
    }

    hasStagedChanges(){
    git::has_staged_changes(){
    ! git diff-index --quiet --cached HEAD
    }

    hasWorkingChanges(){
    git::has_working_changes(){
    # fixes modified but unchanged files from reporting being changed
    git status > /dev/null
    git status > /dev/null
    ! git diff-files --quiet
    }

    hasUntrackedChanges(){
    git::has_untracked_changes(){
    local u=
    ! ( u="$( git ls-files --exclude-standard --others )" && [ -z "${u}" ] )
    }

    runTest
    }
  2. jwliechty revised this gist Oct 6, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gitHelp.sh
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,9 @@ hasStagedChanges(){
    ! git diff-index --quiet --cached HEAD
    }

    hasWorkingChanges(){
    hasWorkingChanges(){
    # fixes modified but unchanged files from reporting being changed
    git status > /dev/null
    ! git diff-files --quiet
    }

  3. jwliechty revised this gist Oct 5, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gitHelp.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,13 @@ runTest(){
    if hasUntrackedChanges; then
    echo "There are untracked changes"
    fi
    if hasAnyChanges; then
    echo 'Repo is dirty!'
    fi
    }

    hasAnyChanges(){
    hasStagedChanges || hasWorkingChanges || hasUntrackedChanges
    }

    hasStagedChanges(){
  4. jwliechty revised this gist Oct 5, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gitHelp.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/bin/bash -e

    # See http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git

    runTest(){
    if hasStagedChanges; then
    echo "There are staged changes"
  5. jwliechty created this gist Oct 5, 2015.
    28 changes: 28 additions & 0 deletions gitHelp.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash -e

    runTest(){
    if hasStagedChanges; then
    echo "There are staged changes"
    fi
    if hasWorkingChanges; then
    echo "There are working changes"
    fi
    if hasUntrackedChanges; then
    echo "There are untracked changes"
    fi
    }

    hasStagedChanges(){
    ! git diff-index --quiet --cached HEAD
    }

    hasWorkingChanges(){
    ! git diff-files --quiet
    }

    hasUntrackedChanges(){
    local u=
    ! ( u="$( git ls-files --exclude-standard --others )" && [ -z "${u}" ] )
    }

    runTest