2

Weird predicament I'm in here. I'm trying to run this code in a cronjob:

cd /home/justi180/public_html; git add *; git commit -m "Auto commit"; git push origin master;

When I run the above in a terminal myself it works. When I run it in a cronjob it doesn't work, however. The output of the cronjob when it tries to commit looks like this:

# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   logs/popularity/daily.json
#       modified:   logs/popularity/monthly.json
#       modified:   logs/popularity/totals.json
#       modified:   logs/popularity/visitors.json
#       deleted:    thisisatest
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)

I've additionally confirmed the job is running as my user by sticking a whoami at the front of the commands. I'm really not sure what to do here; the job is running as the right user and is clearly finding the git command to run, so my normal cron debugging isn't really taking me anywhere.

Justin Flowers
  • 145
  • 2
  • 11

1 Answers1

2

Instead of executing git add * try this :

git add -u 
git add -A 
saurabh14292
  • 1,281
  • 2
  • 10
  • 12
  • Ahh, that was it. The wildcard must have been messing it up, eh? – Justin Flowers Apr 02 '18 at 22:56
  • yes, having * will only "add" the changes to the index but the deleted content will be ignored. Have a look at this answer : https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add This explains the differences between -A -u * and . etc – saurabh14292 Apr 03 '18 at 05:18
  • Yeah I was aware just doing an "add" wouldn't remove deleted content. I was more wondering why the "add *" didn't work before but the "add -A" did, and I think it's because of the wildcard doing funky things in cron. – Justin Flowers Apr 04 '18 at 13:45