Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. tdurand revised this gist Jul 21, 2014. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions set_timestamp_from_commit.sh
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,30 @@
    #!/bin/sh
    OS=${OS:-`uname`}

    if [ "$OS" = 'Linux' ]
    then
    update_file_timestamp() {
    file_time=`git log --no-merges --format=%ai "$1" | head -n 1`
    echo "change timestamp file $file_time $1"
    touch -d "$file_time" "$1"
    }
    elif [ "$OS" = 'FreeBSD' ] || [ "$OS" = 'Darwin' ];
    then
    update_file_timestamp() {
    file_time=`date -r "$(git log --no-merges --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'`
    echo "change timestamp file $file_time $1"
    touch -h -t "$file_time" "$1"
    }
    else
    echo "timestamp changing not implemented" >&2
    exit 1
    fi

    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only`
    #List all the files of the git repository
    for file in `git ls-tree -r --name-only HEAD`
    do
    if [ -f "$file" ]; then
    #For each file update the file timestamp with the timestamp of the last commit on this file
    update_file_timestamp "$file"
    fi
    done
  2. tdurand renamed this gist Jun 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. tdurand renamed this gist Jun 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. tdurand revised this gist Jun 10, 2014. 3 changed files with 1 addition and 35 deletions.
    13 changes: 0 additions & 13 deletions Git hook sync modification time to last commit time
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    Git hook post-merge and post-checkout for sync modification time to last commit time.

    You can download scripts manually and install them yourself, or you can install it with command

    > curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh

    This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.

    You can also start this script manually with environment variable $GIT_MERGE_LIMIT=100 to updated timestamp of last 100 commits for example.

    export GIT_MERGE_LIMIT=100
    /path/to/my/project/.git/hooks/post-merge

    20 changes: 0 additions & 20 deletions install
    Original file line number Diff line number Diff line change
    @@ -1,20 +0,0 @@
    #!/bin/sh

    GIT="/usr/bin/env git"
    CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-toplevel`

    if [ -z "$GITHOME" ]; then
    exit
    fi

    echo "Changind current dir to Git hooks folder"
    cd "$GITHOME"/.git/hooks/ || exit

    echo "Downloading post-merge hook"
    ($CURL $SCRIPT -s > post-merge) || exit

    echo "Installing post-merge hook and post-checkout"
    chmod +x post-merge
    ln -fs post-merge post-checkout
    3 changes: 1 addition & 2 deletions post-merge → set_timestamp
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,7 @@ else
    exit 1
    fi

    LIMIT="-${GIT_MERGE_LIMIT:-1}"
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only $LIMIT`
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only`
    do
    if [ -f "$file" ]; then
    update_file_timestamp "$file"
  5. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -21,5 +21,7 @@ fi
    LIMIT="-${GIT_MERGE_LIMIT:-1}"
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only $LIMIT`
    do
    update_file_timestamp "$file"
    if [ -f "$file" ]; then
    update_file_timestamp "$file"
    fi
    done
  6. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ else
    exit 1
    fi

    LIMIT=${GIT_MERGE_LIMIT:--1}
    LIMIT="-${GIT_MERGE_LIMIT:-1}"
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only $LIMIT`
    do
    update_file_timestamp "$file"
  7. Alexandr Shurigin revised this gist Mar 10, 2014. 2 changed files with 9 additions and 2 deletions.
    8 changes: 7 additions & 1 deletion Git hook sync modification time to last commit time
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,10 @@ You can download scripts manually and install them yourself, or you can install

    > curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh

    This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.
    This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.

    You can also start this script manually with environment variable $GIT_MERGE_LIMIT=100 to updated timestamp of last 100 commits for example.

    export GIT_MERGE_LIMIT=100
    /path/to/my/project/.git/hooks/post-merge

    3 changes: 2 additions & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,8 @@ else
    exit 1
    fi

    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only -1`
    LIMIT=${GIT_MERGE_LIMIT:--1}
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only $LIMIT`
    do
    update_file_timestamp "$file"
    done
  8. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ else
    exit 1
    fi

    for file in `git show --no-commit-id --no-merges --name-only --pretty="format:" -1`
    for file in `git log --no-merges --no-commit-id --pretty="format:" --name-only -1`
    do
    update_file_timestamp "$file"
    done
  9. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ else
    exit 1
    fi

    for file in `git show --no-commit-id --no-merges --name-only --pretty="format:" -2`
    for file in `git show --no-commit-id --no-merges --name-only --pretty="format:" -1`
    do
    update_file_timestamp "$file"
    done
  10. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions post-merge
    Original file line number Diff line number Diff line change
    @@ -4,21 +4,21 @@ OS=${OS:-`uname`}
    if [ "$OS" = 'Linux' ]
    then
    update_file_timestamp() {
    file_time=`git log --format=%ai "$1" | head -n 1`
    file_time=`git log --no-merges --format=%ai "$1" | head -n 1`
    touch -d "$file_time" "$1"
    }
    elif [ "$OS" = 'FreeBSD' ] || [ "$OS" = 'Darwin' ];
    then
    update_file_timestamp() {
    file_time=`date -r "$(git log --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'`
    file_time=`date -r "$(git log --no-merges --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'`
    touch -h -t "$file_time" "$1"
    }
    else
    echo "timestamp changing not implemented" >&2
    exit 1
    fi

    for file in `git show --no-commit-id --name-only --pretty="format:" -2`
    for file in `git show --no-commit-id --no-merges --name-only --pretty="format:" -2`
    do
    update_file_timestamp "$file"
    done
  11. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions install
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,14 @@
    GIT="/usr/bin/env git"
    CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup | exit`
    GITHOME=`$GIT rev-parse --show-toplevel`

    if [ -z "$GITHOME" ]; then
    exit
    fi

    echo "Changind current dir to Git hooks folder"
    cd "$GITHOME" || exit
    cd .git/hooks/ || exit
    cd "$GITHOME"/.git/hooks/ || exit

    echo "Downloading post-merge hook"
    ($CURL $SCRIPT -s > post-merge) || exit
  12. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions install
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,6 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup | exit`

    if [ -z "$GITHOME" ]; then
    exit
    fi

    echo "Changind current dir to Git hooks folder"
    cd "$GITHOME" || exit
    cd .git/hooks/ || exit
  13. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    GIT="/usr/bin/env git"
    CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup`
    GITHOME=`$GIT rev-parse --show-cdup | exit`

    if [ -z "$GITHOME" ]; then
    exit
  14. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup`

    if [ !-n "$GITHOME" ]; then
    if [ -z "$GITHOME" ]; then
    exit
    fi

  15. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ if [ !-n "$GITHOME" ]; then
    fi

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup) || exit
    cd "$GITHOME" || exit
    cd .git/hooks/ || exit

    echo "Downloading post-merge hook"
  16. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup`

    if [ -n "$GITHOME" ]; then
    if [ !-n "$GITHOME" ]; then
    exit
    fi

  17. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,14 @@
    GIT="/usr/bin/env git"
    CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"
    GITHOME=`$GIT rev-parse --show-cdup`

    if [ -n "$GITHOME" ]; then
    exit
    fi

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup || exit) || exit
    cd $($GIT rev-parse --show-cdup) || exit
    cd .git/hooks/ || exit

    echo "Downloading post-merge hook"
  18. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup) || exit
    cd $($GIT rev-parse --show-cdup || exit) || exit
    cd .git/hooks/ || exit

    echo "Downloading post-merge hook"
  19. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup)
    cd .git/hooks/
    cd $($GIT rev-parse --show-cdup) || exit
    cd .git/hooks/ || exit

    echo "Downloading post-merge hook"
    ($CURL $SCRIPT -s > post-merge) || exit
  20. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@ CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup)/.git/hooks/
    cd $($GIT rev-parse --show-cdup)
    cd .git/hooks/

    echo "Downloading post-merge hook"
    ($CURL $SCRIPT -s > post-merge) || exit
  21. Alexandr Shurigin renamed this gist Mar 10, 2014. 1 changed file with 2 additions and 0 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Git hook post-merge and post-checkout for sync modification time to last commit time.

    You can download scripts manually and install them yourself, or you can install it with command

    > curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh
  22. Alexandr Shurigin renamed this gist Mar 10, 2014. 1 changed file with 0 additions and 0 deletions.
  23. Alexandr Shurigin revised this gist Mar 10, 2014. 2 changed files with 6 additions and 1 deletion.
    5 changes: 5 additions & 0 deletions Git hook post-merge and post-checkout
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    You can download scripts manually and install them yourself, or you can install it with command

    > curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh

    This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.
    2 changes: 1 addition & 1 deletion install
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,4 @@ echo "Downloading post-merge hook"

    echo "Installing post-merge hook and post-checkout"
    chmod +x post-merge
    ln -is post-merge post-checkout
    ln -fs post-merge post-checkout
  24. Alexandr Shurigin revised this gist Mar 10, 2014. No changes.
  25. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions install
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/sh

    GIT="/usr/bin/env git"
    CURL="/usr/bin/env curl"
    SCRIPT="https://gist.githubusercontent.com/phpdude/9464925/raw/post-merge"

    echo "Changind current dir to Git hooks folder"
    cd $($GIT rev-parse --show-cdup)/.git/hooks/

    echo "Downloading post-merge hook"
    ($CURL $SCRIPT -s > post-merge) || exit

    echo "Installing post-merge hook and post-checkout"
    chmod +x post-merge
    ln -is post-merge post-checkout
  26. Alexandr Shurigin revised this gist Mar 10, 2014. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions How to install
    Original file line number Diff line number Diff line change
    @@ -1,3 +0,0 @@
    You can download scripts from git and install it manually into .git/hooks/ folder.

    Or make it with automatic installer.
  27. Alexandr Shurigin created this gist Mar 10, 2014.
    3 changes: 3 additions & 0 deletions How to install
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    You can download scripts from git and install it manually into .git/hooks/ folder.

    Or make it with automatic installer.
    24 changes: 24 additions & 0 deletions post-merge
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/sh
    OS=${OS:-`uname`}

    if [ "$OS" = 'Linux' ]
    then
    update_file_timestamp() {
    file_time=`git log --format=%ai "$1" | head -n 1`
    touch -d "$file_time" "$1"
    }
    elif [ "$OS" = 'FreeBSD' ] || [ "$OS" = 'Darwin' ];
    then
    update_file_timestamp() {
    file_time=`date -r "$(git log --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'`
    touch -h -t "$file_time" "$1"
    }
    else
    echo "timestamp changing not implemented" >&2
    exit 1
    fi

    for file in `git show --no-commit-id --name-only --pretty="format:" -2`
    do
    update_file_timestamp "$file"
    done