Skip to content

Conversation

@Ian0sborne
Copy link
Contributor

This PR addresses #945 by including Git information into city config files. A function add_git_info(conf) is introduced, which adds information about the IC tag, upstream remote name, branch name and commit hash to the city config file.

@Ian0sborne
Copy link
Contributor Author

I still haven't finished all the comments, but what do you think of the testing function so far? I wanted to hear your opinion before I committed it.

def test_add_git_info():

    try:
        # keep a copy of the current branch
        current_branch = run_git_command("git branch --show-current")

        # create a testing branch
        testing_branch = 'function-testing-branch'
        run_git_command(f"git checkout -b {testing_branch}")

        # create an empty testing commit
        run_git_command("git commit --allow-empty -m 'create_dummy_commit'")
        testing_commit_hash = run_git_command("git log --pretty=format:%H -n 1") # alternative way of extracting hash

        # create a testing remote upstream
        testing_upstream = 'function-testing-upstream'
        run_git_command(f"git remote add {testing_upstream} .") # use current repo as remote
        run_git_command(f"git branch --set-upstream-to {testing_upstream}/{testing_branch}")
        run_git_command(f"git push -u {testing_upstream} {testing_branch}") # add this otherwise remote = None

        # create a temporary tag for testing
        testing_tag = 'v.function.testing.tag'
        run_git_command(f"git tag {testing_tag}")
        
        extracted_git_info = add_git_info()

        assert extracted_git_info['branch_name']   == testing_branch
        assert extracted_git_info['commit_hash']   == testing_commit_hash
        assert extracted_git_info['upstream_name'] == testing_upstream
        assert extracted_git_info['IC_tag']        == testing_tag

    except Exception as e:
        print(f"Something went wrong: {e}")
        raise

    finally:
        # cleanup happens no matter what, each command is within a try/except so that if one fails the rest still run
        # switches back to the original branch
        try:
            run_git_command(f"git checkout {current_branch}")
        except Exception as e:
            print(f"Failed to restore branch {current_branch}: {e}")
        
        try:
            run_git_command(f"git tag -d {testing_tag}")
        except Exception as e:
            print(f"Failed to delete tag {testing_tag}: {e}")
        # delete local testing branch
        try:
            run_git_command(f"git branch -D {testing_branch}")
        except Exception as e:
            print(f"Failed to delete branch {testing_branch}: {e}")
        # delete remote testing branch
        try:
            run_git_command(f"git push {testing_upstream} --delete {testing_branch}")
        except Exception as e:
            print(f"Failed to delete remote branch {testing_branch} on {testing_upstream}: {e}")

        try:
            run_git_command(f"git remote remove {testing_upstream}")
        except Exception as e:
            print(f"Failed to remove remote {testing_upstream}: {e}")

@gonzaponte
Copy link
Collaborator

Please remind me where we left things here. Is this ready for another review?

@Ian0sborne
Copy link
Contributor Author

Ian0sborne commented Nov 21, 2025

Hey Gonzalo! We still have to commit the new testing function and clean up some of the weird commits we made when testing stuff together. I will get back on it on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants