2017-04-18 4 views
1

Ich möchte dies wie "git beschreiben" arbeitet im Terminal arbeiten.Durchführung git beschreiben in libgit2

Wie bekomme ich aktuelle Tag meiner Repo? Jetzt ist mein Programm druckt

09B8A518

Jedesmal, wenn ich das, ist diese Zahl anders, so ich denke nicht, es ist ID zu begehen oder so.

Als ich „Git beschreiben“ im Terminal durchführen, Ausgang „v0.1.2“

Gibt es eine Möglichkeit, das zu tun?

Übrigens, wie kann ich konvertieren "git_describe_result * out;" stringeln?

string path = C://my/local/repo; 
    string result; 
    git_libgit2_init(); 

    const char * REPO_PATH = path.c_str(); 
    git_repository * repo = nullptr; 
    git_repository_open(&repo, REPO_PATH); 

    git_describe_result *out; 
    git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT; 
    opts.version = GIT_DESCRIBE_FORMAT_OPTIONS_VERSION; // GIT_DESCRIBE_OPTIONS_VERSION; 

    git_describe_workdir(&out, repo, &opts); 
    cout << out << endl; 

    git_describe_result_free(out); 
    git_repository_free(repo); 
    git_libgit2_shutdown(); 
+0

Sie den Zeiger zu drucken. Die wirkliche Frage ist hier, wie 'git_describe_result' als String formatiert wird. –

Antwort

0

Convert git_describe_result in einen String mit git_describe_format.

0

Jetzt funktioniert das für mich

  string path = C://my/local/repo; 
      string result; 
      git_libgit2_init(); 

      const char * REPO_PATH = path.c_str(); 
      git_repository * repo = nullptr; 
      git_repository_open(&repo, REPO_PATH); 
      git_describe_result *out; 
      git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT; 
// --------------------------------------- 
      // I added this 
      opts.describe_strategy = GIT_DESCRIBE_ALL; 
      opts.max_candidates_tags = 0; 
      opts.only_follow_first_parent = 1; 
// --------------------------------------- 
      git_describe_workdir(&out, repo, &opts); 

    // -------------------------------------- 

    // and also this 
       git_buf out1 = { 0 }; 
       const git_describe_format_options opts1=GIT_DESCRIBE_FORMAT_OPTIONS_INIT; 
       git_describe_format(&out1, out, &opts1); 
       result = out1.ptr; 
       cout << result << endl; 

    // --------------------------------------- 
      git_describe_result_free(out); 
      git_repository_free(repo); 
      git_libgit2_shutdown(); 
Verwandte Themen