Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am writing a program that generates a list of git commands that are then passed to a remote server to be executed.

Basically, I want to update remote server local git repository with a given list of branches. If branch has a file that is newer than local, it gets checked out.

But when it gets executed I get 'error: pathspec 'xxx' did not match any file(s) known to git' when the file does exist! This is my code simplified (in bash, for a Linux server):

tmp=/tmp/hotfix$agent
# make sure we are in the right directory and up-to-date with the git repo
echo 'cd ~/my-project; git fetch origin;' > $tmp

# for each branch we want to merge with local
for branch in "${branches[@]}"
do
    echo Working with branch $branch
    # feeding our temporary file with the commands to execute remotely
    cat >> $tmp << NINJA
# get files that are different
git diff origin/$branch --name-status | while read line
do
    # get file path
file=\$(echo "\$line" | sed -e 's/\(M\|A\|D\)   //')
    # get date of last commit for this file in local
local=\$(date +%s --date "\$(git log --date="iso" -1 --reverse \$file | grep ^Date: | sed 's/Date:\s\+//')")
    # get date of last commit for this file in remote branch
remote=\$(date +%s --date "\$(git log origin/$branch --date="iso" -1 --reverse \$file | grep ^Date: | sed 's/Date:\s\+//')")

    # if local file is more recent than remote -- do nothing
[ \$local -gt \$remote ] && {
    echo 'Local is newer than remote -- skipping'
} || {
      # else overwrite local file with remote
    echo 'Remote is newer than local -- merging'
    git checkout -f origin/$issue \$file
}
done

NINJA

done

ssh $agent < $tmp

unlink $tmp

And this is what the remote says:

(stage) ~/my-project > git checkout -f origin/1714 xxx.php error: pathspec 'xxx.php' did not match any file(s) known to git.

When xxx exists

= DEBUG =

This is what I get for example when my script finds out a file has to be created:

 Remote is newer than local -- merging
 We have to add ddl/v1.2.16.sql
 # stat the file to see if it got created ok
 File: `ddl/v1.2.16.sql'
 Size: 12238        Blocks: 24         IO Block: 4096   regular file
 Device: ca01h/51713d   Inode: 310025      Links: 1
 Access: (0664/-rw-rw-r--)  Uid: ( 1***/*****)   Gid: (     ****/******)
 Access: 2013-02-19 10:34:59.181818156 +0000
 Modify: 2013-02-19 10:34:59.173818152 +0000
 Change: 2013-02-19 10:34:59.173818152 +0000
 Birth: -
 Now executing: git checkout -f origin/t1727 ddl/v1.2.16.sql
 error: pathspec 'ddl/v1.2.16.sql' did not match any file(s) known to git.
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.