7

I'm building an application in Ruby on Rails 4 to handle git repositories, kind of like GitHub. One of the features is an in-app text editor with the option to commit your current changes. This is the part where I'm stuck. I need to use Rails to somehow get the changes, commit them, then push them to the remote.

The only thing I've thought of is using a Bash script to do this. The script would just be:

git add -A
git commit -m "Message that I get from user"
git push origin branch_name

The message and branch name would be variables that I get from the user.

For some reason, I don't think this would actually work.

Is it possible to use a Bash script to commit and push a Git repository with Rails? Is there a better, working method to do this?

random
  • 9,774
  • 10
  • 66
  • 83
michaelpri
  • 3,521
  • 4
  • 30
  • 46
  • 7
    https://github.com/schacon/ruby-git Remember, whatever you want to do, someone's probably already written a gem for it. – Michael Hampton Sep 06 '15 at 22:26
  • @MichaelHampton Gah, my Googlefu has failed me :P – michaelpri Sep 06 '15 at 22:27
  • It is a duplicate, but the answer here is more thorough, so even though the other one is older, I'd be tempted to close it in favour of this. – Taryn East Sep 07 '15 at 00:47
  • @MichaelHampton - can you make your comment an actual answer? I can't vote to close the older question until this one has an upvoted answer :) – Taryn East Sep 07 '15 at 00:48
  • @TarynEast I think you have that backwards. I posted an answer. :) – Michael Hampton Sep 07 '15 at 00:54
  • This question is over rated .... You know u there is a gem , or you can use EXEC or any other sys-call methods to excute bash scripts from within you app . – z atef Sep 07 '15 at 01:30
  • @MichaelHampton you posted an answer in the comments-section, not the Answers section. The only actual answer was provided by James (it's below this comment section). I can upvote a comment, but it can't be marked as the "accepted answer" – Taryn East Sep 07 '15 at 02:29
  • @TarynEast I posted an answer on the other question! This one is a duplicate of that one. – Michael Hampton Sep 07 '15 at 02:29
  • This question is more clearly worded and recent and has more upvotes... also the other one is three years old and unlikely to give you an accepted on your answer. I'd rather close the other one in favour of this one... – Taryn East Sep 07 '15 at 02:31

1 Answers1

0

Most languages will let you execute command line expressions and capture the output. This might be lighter weight than installing a gem for every command you might want to run.

[1] Running command line commands within Ruby script

Community
  • 1
  • 1
James
  • 2,742
  • 1
  • 20
  • 43