Merge pull request #70 from TiagoRG/tools-update

[TOOLS] Added git-safe-push
[TOOLS] Fixed README link

[1ano] README update
This commit is contained in:
Tiago Garcia 2023-06-01 22:57:08 +01:00 committed by GitHub
commit f2167403d1
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
5 changed files with 133 additions and 10 deletions

View File

@ -1,11 +1,11 @@
# 1º Semestre # 1º Semestre
## Todo o material das cadeiras do 1º semestre do 1º ano: ## Todo o material das cadeiras do 1º semestre do 1º ano:
- [Fundamentos de Programação](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/fp) | Ano de conclusão: 2022/2023 - [Fundamentos de Programação](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/fp)
- [Introdução à Engenharia Informática](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/iei) | Ano de conclusão: 2022/2023 - [Introdução à Engenharia Informática](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/iei)
- [Introdução aos Sistemas Digitais](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/isd) | Ano de conclusão: 2022/2023 - [Introdução aos Sistemas Digitais](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/isd)
- [Álgebra Linear e Geometria Analítica](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/alga) - [Álgebra Linear e Geometria Analítica](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/alga)
- [Cálculo - 1](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/c1) | Ano de conclusão: 2022/2023 - [Cálculo - 1](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/c1)
--- ---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) *Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -2,11 +2,11 @@
## Todo o material das cadeiras do 1º ano: ## Todo o material das cadeiras do 1º ano:
### [1º Semestre](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre) ### [1º Semestre](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre)
- [Fundamentos de Programação](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/fp) | Ano de conclusão: 2022/2023 - [Fundamentos de Programação](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/fp)
- [Introdução à Engenharia Informática](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/iei) | Ano de conclusão: 2022/2023 - [Introdução à Engenharia Informática](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/iei)
- [Introdução aos Sistemas Digitais](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/isd) | Ano de conclusão: 2022/2023 - [Introdução aos Sistemas Digitais](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/isd)
- [Álgebra Linear e Geometria Analítica](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/alga) |  - [Álgebra Linear e Geometria Analítica](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/alga)
- [Cálculo - 1](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/c1) | Ano de conclusão: 2022/2023 - [Cálculo - 1](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/1semestre/c1)
### [2º Semestre](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre) ### [2º Semestre](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre)

24
tools/git-tools/README.md Normal file
View File

@ -0,0 +1,24 @@
# git-safe-push
## Description
This script is used to push the local changes to the remote repository safely. Instead of pushing directly into the main branch, creates a temporary branch that can be safely deleted after the changes are reviewed and merged. This way you don't have to keep many branches in your remote repository which means it's easier to keep a linear commit history ([Squash and Merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits) suggested for this aswell).
## Usage
Download the script and then add it to bin with the following commands:
```bash
sudo mv git-safe-push /usr/bin
sudo chmod +x /usr/bin/git-safe-push
```
Then you can use it like this:
```bash
git safe-push <remote> <branch> <-n|-e>
```
- `<remote>`: The remote repository to push to.
- `<branch>`: The branch to push to.
- `-n`: Pushes to a new branch.
- `-e`: Pushes to an existing branch.

View File

@ -0,0 +1,99 @@
# Handles the arguments
# git-safe-push <remote (default="origin")> <branch (default=\"temp\")> <-n|-e>
if [ $# -eq 0 ]; then
remote="origin"
branch="temp"
branch_option="-n"
elif [ $# -eq 1 ]; then
remote=$1
branch="temp"
branch_option="-n"
elif [ $# -eq 2 ]; then
remote=$1
branch=$2
branch_option="-n"
elif [ $# -eq 3 ]; then
remote=$1
branch=$2
branch_option=$3
else
echo "Usage: git-safe-push <remote (default=\"origin\")> <branch (default=\"temp\")> <-n/-e>"
exit
fi
if git rev-parse --is-inside-work-tree > /dev/null; then
if git ls-remote --exit-code "$remote" >/dev/null 2>/dev/null; then
# Rebases the repository
git config pull.rebase true
git pull
remote_link=$(git remote get-url "$remote")
link=${remote_link%.git}
if [ "$branch_option" = "-n" ]; then
# Checks if branch exists in the remote
printf "\nChecking for %s...\n\n" "$branch"
exists_in_remote=$(git ls-remote --heads "$remote" "$branch")
# If the branch does not exist
if [ -z "$exists_in_remote" ]; then
# Creates the branch, pushes it and deletes the branch locally
git branch "$branch"
git push "$remote" "$branch"
git branch -d "$branch" >/dev/null 2>/dev/null
# Prints output message
printf "\n----------------------------------------------------------------\n\n Branch does not yet exist, pushed to %s/%s...\n\n You can now create a pull request at:\n > %s/compare/%s\n\n----------------------------------------------------------------\n\n" "$remote" "$branch" "$link" "$branch"
else
# Makes sure to get a free indexed temporary branch
for i in $(seq 1 100) ; do
# Checks if branch exists in the remote
printf "Checking for %s...\n" "$branch$i"
exists_in_remote=$(git ls-remote --heads "$remote" "$branch$i")
# If the branch does not exist
if [ -z "$exists_in_remote" ]; then
# Creates the branch, pushes it and deletes the branch locally
git branch "$branch$i"
git push "$remote" "$branch$i"
git branch -d "$branch$i" >/dev/null 2>/dev/null
break
else
printf "Branch already exists, trying again...\n\n"
fi
done
# Prints output message
printf "\n----------------------------------------------------------------\n\n Branch does not yet exist, pushed to %s/%s...\n\n You can now create a pull request at:\n > %s/compare/%s\n\n----------------------------------------------------------------\n\n" "$remote" "$branch$i" "$link" "$branch$i"
fi
else
# Checks if branch exists in the remote
printf "\nChecking for %s...\n" "$branch"
exists_in_remote=$(git ls-remote --heads "$remote" "$branch")
# If the branch does not exist
if [ -z "$exists_in_remote" ]; then
printf "\n----------------------------------------------------------------\n\n Branch does not exist, aborting...\n\n----------------------------------------------------------------\n\n"
exit
fi
# Creates the branch, pushes it and deletes the branch locally
git branch "$branch"
result=$(git push "$remote" "$branch")
if ! echo "$result" | grep -q "Everything up-to-date"; then
git branch -d "$branch" >/dev/null 2>/dev/null
printf "\n----------------------------------------------------------------\n\n Branch is up-to-date, aborting...\n\n----------------------------------------------------------------\n\n"
exit
elif ! echo "$result" | grep -q "To $remote.git"; then
git branch -d "$branch" >/dev/null 2>/dev/null
printf "\n----------------------------------------------------------------\n\n Pushed to %s/%s...\n\n You can now create a pull request at:\n > %s/compare/%s\n\n----------------------------------------------------------------\n\n" "$remote" "$branch" "$link" "$branch"
else
git branch -d "$branch" >/dev/null 2>/dev/null
printf "\n----------------------------------------------------------------\n\n Failed to push to %s/%s, aborting...\n\n----------------------------------------------------------------\n\n" "$remote" "$branch"
exit
fi
fi
else
printf "\nRemote %s is unreachable for this repository.\nIf you pretend to use a different remote name specify it using: git-safe-push <remote>\nIf this is the correct name, check if the current remote url is correct.\n" "$remote"
fi
else
printf "You are currently not in a git repository."
fi

View File

@ -6,7 +6,7 @@
#### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/ttb) and download the zip folder. #### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/ttb) and download the zip folder.
#### 2. Extract it into any location and then open that location. #### 2. Extract it into any location and then open that location.
#### 3. Inside the directory, right click and choose "Open in terminal" #### 3. Inside the directory, right click and choose "Open in terminal"
![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/master/tools/truthtable/openInTerminal.png) ![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/main/tools/truthtable/openInTerminal.png)
#### 4. Run the following commands: #### 4. Run the following commands:
1. Make sure the setup.sh is executable: `sudo chmod +x setup.sh`<br> 1. Make sure the setup.sh is executable: `sudo chmod +x setup.sh`<br>
2. Install the script: `./setup.sh install` 2. Install the script: `./setup.sh install`