From fdf63d294ecd594340e87f70b15d628121f3172b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20Tudor=20CRAINEA?= Date: Sat, 17 Mar 2018 02:14:06 +0200 Subject: [PATCH 1/3] Add initial version of git-help.c --- Makefile | 7 +++++++ README.md | 35 ++++++++++++++++++++--------------- git-help.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 Makefile create mode 100644 git-help.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9aad4ee --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: git-help + +git-help: git-help.o + +.PHONY: clean +clean: + -rm -f git-help git-help.o diff --git a/README.md b/README.md index 3e1acaf..b00aef4 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ -# Welcome the git tutorial Introduction! -This tutorial aims to teach you how to use `git` in an efficient manner for -your projects. This guide does not focus on `git` commands, but rather on -the things you need to do in order to write code in an easy to maintain -fashion. +# Welcome the git help tutorial! +The `git-help` tool found in this repository can be ran to find out more +information about git commands. -## Identity -When using `git` for the first time, the first step you need to do is to -identify yourself, so that whoever is interested in the portion of code you -wrote, they can easily reach you for further questions. In order to identify -yourself, you need to specify your name and email address to the `git` engine. -This is intuitively done using the `git config` command: +## Compile +You can compile the program using the `Makefile` in this project: ``` -git config --global user.name "YOUR NAME" -git config --global user.email "YOUR@EMAIL.ADDRESS" +make +``` +will generate the `git-help` executable. + +## Usage +When ran without parameters, the program returns the man page of the main git +command: +``` +./git-help +``` + +The program can also receive a parameter that indicates which command we want +to get more information about: +``` +./git-help commit ``` -Run these commands on your local computer; make sure you use a valid name and -email address! diff --git a/git-help.c b/git-help.c new file mode 100644 index 0000000..48ac005 --- /dev/null +++ b/git-help.c @@ -0,0 +1,29 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +int main(int argc, char **argv) +{ + char *cmd; + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); + exit(-1); + } + + system("man git"); + return 0; +} From 510a79a6d61d0517ea9fe68311eda166551dcf15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20Tudor=20CRAINEA?= Date: Sat, 17 Mar 2018 12:45:07 +0200 Subject: [PATCH 2/3] Add parameter support for different git commands --- git-help.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/git-help.c b/git-help.c index 48ac005..3bbff26 100644 --- a/git-help.c +++ b/git-help.c @@ -19,11 +19,23 @@ int main(int argc, char **argv) { char *cmd; - if (argc > 1) { - fprintf(stderr, "Usage: %s\n", argv[0]); + if (argc > 2) { + fprintf(stderr, "Usage: %s [command]\n", argv[0]); exit(-1); } - system("man git"); + if (argc == 1) + system("man git"); + else { + cmd = malloc(7 + strlen(argv[argc])); + if (!cmd) { + fprintf(stderr, "not enought memory to create command!\n"); + exit(-1); + } + strcpy(cmd, "man git-"); + strcat(cmd, argv[argc]); + system(cmd); + } + return 0; } From 02a28f8ca48eceee206303f6f1f63c87b54e51f1 Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Sat, 7 Mar 2020 11:25:16 +0200 Subject: [PATCH 3/3] Fix missing null termination space --- git-help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-help.c b/git-help.c index 3bbff26..5cd7ab1 100644 --- a/git-help.c +++ b/git-help.c @@ -27,7 +27,7 @@ int main(int argc, char **argv) if (argc == 1) system("man git"); else { - cmd = malloc(7 + strlen(argv[argc])); + cmd = malloc(9 + strlen(argv[argc])); if (!cmd) { fprintf(stderr, "not enought memory to create command!\n"); exit(-1);