alexcory Posted March 29, 2014 Share Posted March 29, 2014 (edited) Why does this work in if I put it in a Terminal Command but not in a Run Script set to /bin/bash/? # -- Step 1: Sync Local Directories -- rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/; # rm -r .DS_Store; # -- Step 2: Push Changes To Github -- ~/path/to/local/git\ repository/for/directory1/; git add *; git commit -m "{query}"; git push --all Edited March 29, 2014 by AleXander Link to comment
jdfwarrior Posted March 29, 2014 Share Posted March 29, 2014 Why does this work in if I put it in a Terminal Command but not in a Run Script set to /bin/bash/? # -- Step 1: Sync Local Directories -- rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/; # rm -r .DS_Store; # -- Step 2: Push Changes To Github -- ~/path/to/local/git\ repository/for/directory1/; git add *; git commit -m "{query}"; git push --all Try using full path rather than relative paths or paths beginning with ~. See if that fixes it. alexcory 1 Link to comment
alexcory Posted March 29, 2014 Author Share Posted March 29, 2014 Try using full path rather than relative paths or paths beginning with ~. See if that fixes it. I tried and didn't have any luck. Any other ideas? Link to comment
jdfwarrior Posted March 30, 2014 Share Posted March 30, 2014 I tried and didn't have any luck. Any other ideas? Double checked to ensure that the escaping options are set correctly? Those will get ya every time... Link to comment
alexcory Posted March 30, 2014 Author Share Posted March 30, 2014 Double checked to ensure that the escaping options are set correctly? Those will get ya every time... I'm pretty sure it's not a good idea to put cd in there but it made it work properly without opening the terminal every time. It ended up looking like this. # -- Step 1: Sync Local Directories -- rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/; # rm -r .DS_Store; # -- Step 2: Push Changes To Github -- cd ~/path/to/local/git\ repository/for/directory1/; git add *; git commit -m "{query}"; git push --all Is it not good practice to put the cd in there? Can it cause problems or anything? Link to comment
jdfwarrior Posted March 31, 2014 Share Posted March 31, 2014 I'm pretty sure it's not a good idea to put cd in there but it made it work properly without opening the terminal every time. It ended up looking like this. # -- Step 1: Sync Local Directories -- rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/; # rm -r .DS_Store; # -- Step 2: Push Changes To Github -- cd ~/path/to/local/git\ repository/for/directory1/; git add *; git commit -m "{query}"; git push --all Is it not good practice to put the cd in there? Can it cause problems or anything? Nothing wrong with using cd. Link to comment
deanishe Posted April 4, 2014 Share Posted April 4, 2014 It's possible that the discrepancy between your shell environment (set up by .bashrc, .profile etc.) and the one Alfred uses (launchd's environment) is causing the problem. Where are your git and rsync commands? In /usr/bin or /usr/local/bin? alexcory 1 Link to comment
rice.shawn Posted April 4, 2014 Share Posted April 4, 2014 It's possible that the discrepancy between your shell environment (set up by .bashrc, .profile etc.) and the one Alfred uses (launchd's environment) is causing the problem. Where are your git and rsync commands? In /usr/bin or /usr/local/bin? Another problem based on that shell is how the .git directories are read. I ran into this problem with the workflow processing script on Packal. It was written in PHP, but it just invoked the git commands via shell commands, so here is the relevant github code: // Add all the files $command = "git --git-dir $github/.git --work-tree $github/ add $github/*"; exec($command); // Commit changes $command = "git --git-dir=$github/.git --work-tree $github/ commit -am 'updated for $bundle version: $version'"; exec($command); // Push it to the repo $command = "git --git-dir=$github/.git --work-tree $github/ push origin"; exec($command); Obviously, you don't have those variables. The "$github" variable is just the full path to the local git repo. alexcory 1 Link to comment
alexcory Posted April 25, 2014 Author Share Posted April 25, 2014 Another problem based on that shell is how the .git directories are read. I ran into this problem with the workflow processing script on Packal. It was written in PHP, but it just invoked the git commands via shell commands, so here is the relevant github code: // Add all the files $command = "git --git-dir $github/.git --work-tree $github/ add $github/*"; exec($command); // Commit changes $command = "git --git-dir=$github/.git --work-tree $github/ commit -am 'updated for $bundle version: $version'"; exec($command); // Push it to the repo $command = "git --git-dir=$github/.git --work-tree $github/ push origin"; exec($command); Obviously, you don't have those variables. The "$github" variable is just the full path to the local git repo. It's possible that the discrepancy between your shell environment (set up by .bashrc, .profile etc.) and the one Alfred uses (launchd's environment) is causing the problem. Where are your git and rsync commands? In /usr/bin or /usr/local/bin? `git` is in both `usr/local/bin` and `usr/bin/`. The same thing goes for `rsync`. At least I was able to see both of them in both directories. Could you walk through what's going on in those commands? Does the " --git-dir " portion return the git repository that you're currently selecting? What does the " --work-tree do? How does the ".git" work? The .git part is mostly what's throwing me off I think. // Add all the files $command = "git --git-dir $github/.git --work-tree $github/ add $github/*"; exec($command); Link to comment
deanishe Posted April 25, 2014 Share Posted April 25, 2014 Chances are, when you run the command from Terminal, /usr/local/bin will be first on your PATH (use echo $PATH to find out), so calling git or rsync in a script will run the versions in /usr/local/bin. Alfred, however, ignores your PATH and will use the git and rsync in /usr/bin. I'm guessing you installed git and rsync from homebrew or the like, so they're almost certainly newer versions that the system ones. It's possible one of your options isn't understood by the older versions. You should always use full paths, e.g. /usr/bin/git not just git in workflow scripts to ensure you're using the same executables from Terminal and Alfred. .git is the folder that git creates when you make a directory a git repository. It's where .git keeps all its data. Remove that folder and you no longer have a repository. The --git-dir and --work-tree options tell git which directory it should operate on. By default, it uses the current working directory and searches up the file tree till it finds a .git directory. Personally, I wouldn't bother with those, but would do a chdir to the repository directory and just run /usr/bin/git add .. You might have to chdir back to the previous working directory afterwards (which is the workflow root directory when run from Alfred). alexcory 1 Link to comment
rice.shawn Posted April 27, 2014 Share Posted April 27, 2014 Chances are, when you run the command from Terminal, /usr/local/bin will be first on your PATH (use echo $PATH to find out), so calling git or rsync in a script will run the versions in /usr/local/bin. Alfred, however, ignores your PATH and will use the git and rsync in /usr/bin. I'm guessing you installed git and rsync from homebrew or the like, so they're almost certainly newer versions that the system ones. It's possible one of your options isn't understood by the older versions. You should always use full paths, e.g. /usr/bin/git not just git in workflow scripts to ensure you're using the same executables from Terminal and Alfred. .git is the folder that git creates when you make a directory a git repository. It's where .git keeps all its data. Remove that folder and you no longer have a repository. The --git-dir and --work-tree options tell git which directory it should operate on. By default, it uses the current working directory and searches up the file tree till it finds a .git directory. Personally, I wouldn't bother with those, but would do a chdir to the repository directory and just run /usr/bin/git add .. You might have to chdir back to the previous working directory afterwards (which is the workflow root directory when run from Alfred). What Dean said. If you want to do anything to the Git repository when you're not in that directory, then you need to specify the git-dir and the worktree. If you cd to the directory, then you can just run git without specifying those flags. If you do have more than one version of git / rsync installed, and if you need to use a specific one, then use the full path like Dean mentioned. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now