Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3348844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:35:31+00:00 2026-05-18T01:35:31+00:00

Whenever I commit, I worry that I may have missed out a dependency and

  • 0

Whenever I commit, I worry that I may have missed out a dependency and I’m looking for the simplest way to test my git tree in isolation to ensure whatever is in the git index (“staged”) will in fact compile/run on their own.

My code’s dependencies exist in the filesystem from where I do the ‘git add’ and so simple compiling and running tests doesn’t guarantee that whatever I checkin would compile/run if the tree (or staging area) was checkout out onto a clean filesystem.

I could have a continuous build that would check after submission but I prefer not to have any bad commits in the history that I later have to patch. I therefore want a way of creating an isolated environment that includes a checkout of the tree as well as the index/staging area.

One thing I’ve considered is using git stash twice, i.e.:

  1. Invoke ‘git stash’ to save the files in the index
  2. Somehow get a list of the files not tracked, ‘git add’ all these files, save a new stash
  3. Delete all the previously untracked files
  4. Restore the original stash
  5. I should now have a clean environment that has only the code already checked-in and the code in the staging area which I can compile & test.
  6. Once finished, I restore the stash of the untracked files and then untrack them to leave me in the same position that I was in originally.

(These untracked files may be useful but not necessarily things I want to check in to the repository – e.g. eclipse projects).

I have a feeling I’m overengineering a simple problem, though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:35:31+00:00Added an answer on May 18, 2026 at 1:35 am

    Install this script (or something like it — mine is stolen too) as a pre-commit hook. It copies the index to a temporary working dir and runs a build there. It will catch files that you’ve missed.

    I know there are at least one or two other SO questions that address this exact issue — testing/validating the index instead of the working dir in a pre-commit hook — but I can’t seem to find them right now.

    (For completeness, I’ve got this script in my repo as .git-hooks/pre-commit/test-the-index; there are a couple of other scripts there. See below for what I’m using as .git/hooks/pre-commit.)

    #!/bin/sh
    #
    # Via: http://github.com/jwiegley/git-scripts/blob/master/pre-commit.sh
    #
    
    if [ ! $(git rev-parse --symbolic-full-name HEAD) = refs/heads/master ]; then
        exit 0
    fi
    
    # These are the locations I keep my temporary source and build trees in
    TMPDIR=$HOME/code/myproject-pre-commit
    MIRROR=$HOME/code/myproject-pre-commit-mirror
    
    # Exit with status 1 if any command below fails
    set -e
    
    # Checkout a copy of the current index into MIRROR
    git checkout-index --prefix=$MIRROR/ -af
    
    # Remove files from MIRROR which are no longer present in the index
    git diff-index --cached --name-only --diff-filter=D -z HEAD | \
        (cd $MIRROR && xargs -0 rm -f --)
    
    # Copy only _changed files_ from MIRROR to TMPDIR, without copying timestamps.
    # This includes copying over new files, and deleting removed ones.  This way,
    # "make check" will only rebuild what is necessary to validate the commit.
    rsync -rlpgoDOc --delete --exclude-from=.git-hooks/excludes $MIRROR/ $TMPDIR/
    
    # Everything else happens in the temporary build tree
    cd $TMPDIR
    
    nosetests
    
    exit 0
    

    This is my actual .git/hooks/pre-commit:

    #!/bin/bash
    
    set -e
    for hook in $(find .git-hooks/pre-commit -perm /u+x,g+x,o+x -type f -not -name '*~' 2>/dev/null)
    do
      echo "@@ Running hook: $(basename $hook)"
      $hook "$@"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new version branch and my trunk. Whenever I commit a bug
Whenever I design a database, I always wonder if there is a best way
Whenever I use the signal/slot editor dialog box, I have to choose from the
I am trying to add a post-commit hook to a bare repository, such that
Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks
Right now, whenever I make a commit with svn, I use the -m option
Whenever I use a variable name that stands for a primary key as int
Whenever I try to add a new project to my SourceSafe repository it creates
Whenever I indent HTML in PHP mode, emacs (22.1.1, basic install on Redaht Linux
Whenever I type a (, [, or {, Notepad++ completes it with the corresponding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.