Hot answers tagged

16 votes
Accepted

Git delete all merged in local branches

Improve your file handling: Don't use a hard coded file name for temporary files. Don't spew temporary files into the current directory. Make sure you clean up temporary files even on error. The ...
user avatar
  • 1,203
14 votes
Accepted

Clone GitHub repository using Python

requests is third-party, so (per the style guide) there should be a blank line in the imports: import os import requests <...
user avatar
  • 13.8k
14 votes
Accepted

Taking YouTube links out of a list of GitHub repo READMEs

Here are some concerns/suggestions: you are reading the file twice - once to get the row count and when reading the links. And, you don't need to initialize the ...
user avatar
  • 17.1k
14 votes

Git delete all merged in local branches

DRY - don't repeat yourself "Don't repeat yourself" is a popular programming principle. You could apply it here by not repeating your filename over and over. ...
user avatar
  • 2,706
14 votes

Git Push Bash script

Rather than make it interactive read -p "Continue? " yn I would make this more like other command line tools. You have default values and allow ...
user avatar
  • 91.7k
13 votes
Accepted

Bash script to simplify Git deployment workflow

Use exit codes directly Instead of this: merge $SOURCE_BRANCH 'staging' status=$? if [ $status -ne 0 ] then echo "ERROR: STEP 1" >&2 exit 1 fi You ...
user avatar
  • 107k
12 votes
Accepted

Date of latest GitHub project release

You're actually writing in C but using some C++ features, I'd drop C style (and functions) in favor of their C++ counterparts: 1) Even if you're using a C API you should write C++ classes to hide ...
user avatar
12 votes
Accepted

Avoiding shell injection when calling Git in Python

Your defense strategy is known as "enumerating badness". As a rule, any strategy based on enumerating badness is doomed to fail. For example, you prohibit rm -rf /...
user avatar
10 votes
Accepted

Git pre-commit hook to check that changes to certain files only happen on the master branch

Use fewer abbreviations. It's certainly not bad in this case, but small stuff like production instead of prod (unless perhaps it'...
user avatar
  • 32.9k
10 votes

Date of latest GitHub project release

Your code can benefit from RAII. For example by creating a small HInternet struct with a destructor to hold a single HINTERNET. ...
user avatar
9 votes
Accepted

Bash function to parse git status

Porcelain format As @Vogel612 noted, the --porcelain format is the right one to use for scripting: The porcelain format is similar to the short format, but is ...
user avatar
7 votes
Accepted

Use git to get SHA-1 of repo

It seems to me that this would be equivalent but shorter: ...
user avatar
  • 107k
7 votes
Accepted

Git commit-msg URL shortener

First of all, the `cmd` form of running commands and capturing their output is deprecated. Use the recommended, modern way everywhere: ...
user avatar
  • 107k
7 votes
Accepted

Walking Git History

CommitVisitor Using Set<T>.Contains() and returning if it evaluates to truemakes the intent of the code more clear but ...
user avatar
  • 50k
7 votes

Git delete all merged in local branches

I am assuming you are starting nano so that you may remove possible occurrences of master branch (or some other static branch) ...
user avatar
  • 8,673
7 votes
Accepted

A Python script that generates git commits for the last year

Python is actually well-known for having a unified style-guide. It is called PEP8. It has both general advice as well as specific advice (naming and such). flake8 ...
user avatar
  • 40.6k
6 votes
Accepted

Python-based Git pre-commit hook to manage multiple users/Git identities

Architecture / general thoughts Overall looks good. You have lots of mostly useful comments which help to understand the program, the code is clear if a little verbose, so to me this was easy to ...
user avatar
  • 11k
6 votes

Git Push Bash script

If you're going to keep your script interactive, I'd reorder these lines: git add . read -r -p "Commit name/number/identifier: " NUM to ...
user avatar
  • 149
5 votes
Accepted

Bash script to clone all public repos or gists for a specified user, optionally to a directory of choice

It's not a bad attempt, though full of duplicated code and some bad practices. Checking if a program exists You do this kind of thing several times: ...
user avatar
  • 107k
5 votes

Git pre-commit hook to check that changes to certain files only happen on the master branch

Some notes: zone_files.keys.each and then zone_files[key]. You should iterate the pair: ...
user avatar
  • 11.1k
5 votes
Accepted

Bash script to remove unwanted git objects

The shebang: #!/usr/bin/env bash is not needed. env is used to modify the working environment, and since you don't use any of ...
user avatar
  • 843
5 votes

Use git to get SHA-1 of repo

Since Janos already gave a nice review on the actual workings of the code, I'll just add some nitpicks: The python style-guide (PEP-8) defines the maximum line-length to be 79 characters for code (...
user avatar
  • 25k
5 votes
Accepted

POSIX shell script using a string to store command arguments

First thing, you could turn the check if the checkbashisms tool is installed into a guard clause, shaving off one level of indentation: ...
user avatar
5 votes

Install, configure, and maintain content for Ubuntu webserver

So, this might not be quite in line with your 100% automation approach, but the best way to provide a shell script access to a git repository is to use ssh keys to allow access to your git repository. ...
user avatar
  • 30.7k
5 votes
Accepted

Tracking 1400+ client codes, multi-threading nightmare

First, I'm pretty sure that it's impossible for os.chdir(path) to meaningfully apply different working directories per thread; and even if it were possible it ...
user avatar
5 votes

Git Push Bash script

Do you really expect the user to type in REMOTE and BRANCH, copying the output of the previous commands? What if the user makes a typo? Why bothering the user at all? Instead of ...
user avatar
4 votes

Python script that does a git diff

if result is False: raise Exception('diff found between the files') else: return 'files are identical' Why would a difference be considered ...
user avatar
  • 13.8k
4 votes
Accepted

Adding SecureString support to Lib2GitSharp

I don't see a problem with how the SecureString objects are handled - seems pretty solid to me, but I've never used those so I'm possibly missing something that ...
user avatar
4 votes

Ruby script to create git repos

The structure is kinda confusing. empty_name? does a lot more than just tell you if the name's empty, and so does folder_exists?....
user avatar
  • 32.9k
4 votes
Accepted

Small CLI note manager and publisher

Per the style guide, your imports should look like: ...
user avatar
  • 13.8k

Only top scored, non community-wiki answers of a minimum length are eligible